简体   繁体   中英

PHP WordPress Plugin - How to display a div on the static homepage only?

This is my first time building a plugin for WordPress. I got the basics down but now I am trying to display a div on the bottom right corner, more like a small pop-up on the bottom right side of the front page only. The PHP code that I've uploaded did not work, it kept crashing my website.

Where is my mistake?

Please explain your answers. Thank you!

Code:

<?php
/*
Plugin Name: My First Plugin
Plugin URL: http://www.martinshabacom.ipage.com/test
Description: An awesome facebook popup plugin that will amaze you!
Author: Martin
Version: 1.0
Author URL: http://www.martinshabacom.ipage.com/test
*/
add_action('admin_menu', 'myfirstplugin_admin_actions');
function myfirstplugin_admin_actions() {
    add_options_page('MyFirstPlugin', 'MyFirstPlugin', 'manage_options', __FILE__, 'myfirstplugin_admin');
}

function myfirstplugin_admin()
{
?>
<style>
    .wrap { 
        width:100%;
        height:auto;
        }

    .popup {
        position:fixed;
        bottom:0;
        right:0;
        width:325px;
        height:200px;
        background-color:#09f;
    }
</style>


    <div class="wrap">

    <h1>Hello World!</h1><br>
    <h4>Hope you like my awesome popup!</h4>

    </div>



<?php if(is_front_page()) {
        <div class="popup">Testing Div Tag On The Bottom Right Corner...</div>
    }
?>
<?php
}
?>

The following part should not be inluded the PHP if clause..

<div class="popup">Testing Div Tag On The Bottom Right Corner...</div>

Generally I think it's better to use alternative syntax to make your code more readable:

<?php if (...) : ?> 
      your html code
<?php endif; ?>

Reference: http://php.net/manual/en/control-structures.alternative-syntax.php

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM