I want to run some code on every page request in WordPress. I used the init and shutdown actions, but on one page it is calling the method twice somehow. Is there an alternative or better approach in PHP in WordPress.
Leave a Reply
You must be logged in to post a comment.
Mike, assuming that by page request you mean the front part of it (not including the admin hits) then
wp_footer
is the best place toadd_action()
to.Calling the method twice could mean a few things (off the top of my head):
init
action just like any other request.init
action as wellTo debug that you could try and output or log the contents of the
$_REQUEST
array to see why it’s being fired twice.Cheers.
You can simply do that in the
page.php
file of your selected theme. That php code is executed for displaying each page. If you want to execute some code for posts then usesingle.php
.