0

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.com/f/partner"><img src="//cdn.mxpnl.com/site_media/images/partner/badge_white.png" alt="Mobile Analytics" /></a>';

     } 
    add_action( 'wp_footer', 'mixpanel_footer' );
3
  • 1
    Please post the code you're using so we can have a better idea of what you're trying to do. 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 Commented Aug 3, 2013 at 9:03

3 Answers 3

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.

0

Try adding priority to hook as following:

function mixpanel_footer(){

echo '<a style="margin-left:45%;" href="https://mixpanel.com/f/partner"><img src="//cdn.mxpnl.com/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.

4
  • I tried it before but it didn't work either. Commented Aug 3, 2013 at 10:30
  • Is other functionality of plugin working well? Commented Aug 3, 2013 at 10:40
  • I have added this code in the plugin file hello.php of Hello Dolly plugin and it worked well. Is there anything wrong in your plugin code? Commented Aug 3, 2013 at 10:45
  • @WaseemAbuSenjer - If you view the source of the page, is the HTML being added? It's possible the hook is echoing properly but is hidden due to styles. Also, try adding a priority higher than 5.
    – BODA82
    Commented Dec 10, 2014 at 16:58
0

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' );
1
  • Why would that help? There's no separate action to do in the original code. The original code is a wp_footer handler just like you've written.
    – Rup
    Commented Oct 18, 2021 at 8:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.