6

In my themes functions.php file I have put:

add_action('wp_footer', 'method');

function method()
{
echo "this is being called";
die();
}

My wordpress footer.php file looks like this:

<?php wp_footer(); ?>
</body>
</html>

What could be the reason my add_action hook is not being called?

I can provide additional code or information if needed.

EDIT:

Instead of die() if I echo a script it won't appear in the pages footer

add_action('wp_footer', 'method');

function method()
{
echo "<script>...</script>";
}
7
  • 2
    why are you using die()? perhaps that is your problem. Commented Jun 15, 2015 at 13:40
  • I want to see if it is being called. If I put echo '<script>..</script>', save it and inspect the page I don't find the script in the footer Commented Jun 15, 2015 at 13:42
  • Pretty sure KnightHawk is right. You are likely killing the application before it generates output.
    – jdm2112
    Commented Jun 15, 2015 at 13:43
  • I apologize. die() was a bad example Commented Jun 15, 2015 at 13:46
  • Are you checking it in Dashboard?? (probably you aren't :) ). If yes, use admin_footer hook for it.
    – Domain
    Commented Jun 15, 2015 at 13:56

2 Answers 2

12

In a WordPress footer hooks are different for back-end(dashboard) and front-end.

In Dashboard use "admin_footer" hook.

In Front-end use "wp_footer" hook.

1
  • Argh, this seems so easy and still I failed to remember! Thank you. Can't I upvote 3 or 4 times? :D :D
    – Erenor Paz
    Commented Nov 18, 2016 at 15:00
0

With such a general function name like method() a collision could be happening. Try something a little more unique than that. Also, if you have access to the server you could also print it to the error log so you don't have to worry when the page is being rendered.

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.