简体   繁体   中英

Wordpress Plugin: Display div on static homepage

I'm in the process of a building a small WordPress bottom right corner popup. I ran into some trouble. This is my first time building a WordPress plugin. Anyways, I can't figure out how to show it on the front static page of my website. Please help?

This is the only file I have in my Plugin folder. Where is my mistake?

Here's my 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>


    <div class="popup">
<?php if(is_front_page()) {
        Hello world
    }
?>
    </div>

<?php
}
?>

I think you want to add output to the footer using the wp_footer action, not the admin_menu. The wp_footer is used to add output when the wp_footer() method is called by your theme. It's a useful place for floating elements on the website.

So it would be

add_action('wp_footer', 'myfirstplugin_admin_actions');

and make sure your theme has the <?php wp_footer() ?> line somewhere appropriate.

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