2

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>";
}
  • 1
    why are you using die()? perhaps that is your problem. – KnightHawk Jun 15 '15 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 – BDillan Jun 15 '15 at 13:42
  • Pretty sure KnightHawk is right. You are likely killing the application before it generates output. – jdm2112 Jun 15 '15 at 13:43
  • I apologize. die() was a bad example – BDillan Jun 15 '15 at 13:46
  • Are you checking it in Dashboard?? (probably you aren't :) ). If yes, use admin_footer hook for it. – WisdmLabs Jun 15 '15 at 13:56
7

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.

  • 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 Nov 18 '16 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, privacy policy and cookie policy

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