admin管理员组

文章数量:1279246

I'm using the wp_footer hook into the plugin and it doesn't work, but when I copy the code to the "functions.php" file of the active theme it does work, what is the possible problem in this situation ?

    function mixpanel_footer(){

echo '<a style="margin-left:45%;" href=""><img src="//cdn.mxpnl/site_media/images/partner/badge_white.png" alt="Mobile Analytics" /></a>';

     } 
    add_action( 'wp_footer', 'mixpanel_footer' );

I'm using the wp_footer hook into the plugin and it doesn't work, but when I copy the code to the "functions.php" file of the active theme it does work, what is the possible problem in this situation ?

    function mixpanel_footer(){

echo '<a style="margin-left:45%;" href="https://mixpanel/f/partner"><img src="//cdn.mxpnl/site_media/images/partner/badge_white.png" alt="Mobile Analytics" /></a>';

     } 
    add_action( 'wp_footer', 'mixpanel_footer' );
Share Improve this question edited Aug 3, 2013 at 9:02 Waseem Abu Senjer asked Aug 3, 2013 at 2:51 Waseem Abu SenjerWaseem Abu Senjer 2433 silver badges10 bronze badges 3
  • 1 Please post the code you're using so we can have a better idea of what you're trying to do. – Morgan Estes Commented Aug 3, 2013 at 4:14
  • are you hooking the code when you put it into functions.php? if not maybe your theme doesn't have wp_footer in the footer.php Without code that's my first guess. – Brooke. Commented Aug 3, 2013 at 4:40
  • I updated the question, Yes I'm pretty sure that the theme has wp_footer in footer.php, that's why it's working when I put the code in functions.php – Waseem Abu Senjer Commented Aug 3, 2013 at 9:03
Add a comment  | 

3 Answers 3

Reset to default 1

Firstly, remove the margin-left CSS property from your html and then try if it works. May be your html is being hidden behind any other html.

Or better try this first -

Remove the current code from your function and just write any non html thing. Then put a die() or exit() and see if it's being rendered properly. Then you can do further debugging.

Try adding priority to hook as following:

function mixpanel_footer(){

echo '<a style="margin-left:45%;" href="https://mixpanel/f/partner"><img src="//cdn.mxpnl/site_media/images/partner/badge_white.png" alt="Mobile Analytics" /></a>';

 } 
add_action( 'wp_footer', 'mixpanel_footer', 5 );

For more information on adding priority to wp_footer hook visit this page.

Can you please use this code? I think it will work properly.

function your_function(){
    do_action( 'your_action' );
}
add_action( 'wp_footer', 'your_function' );

本文标签: using wpfooter hook in a plugin