I noticed that when I hook into ‘wp’ it seems to be firing twice — for example
add_action('wp', 'just_testing');
function just_testing(){
global $post;
error_log($post->ID);
}
returns into my error_log the following two entries:
[01-Feb-2013 13:06:58 UTC] 1120
[01-Feb-2013 13:06:58 UTC]
I searched google and stackexchange and the thread “What would cause the ‘wp’ action to fire twice per page (but only once per post) in Firefox only?” does not apply because I am getting the two firings in all browsers.
Thanks for any help!
It can happen if one of the files you include in the theme is returning 404 Not Found error. Like, if you’re linking to a .js or .css or an image which does not exist on that location. Use the Inspector in your browser to see if you get any 404 errors, anywhere.
Fix them and try again.
Search for
'wp'
, and"wp"
(quotes included) in the files of your plugins directory and sub-directories (defaultwp-content/plugins
) and your current theme’s directory and sub-directories (defaultwp-content/themes/YOUR-THEME
).In WP core files (3.5), the
wp
action is only fired once, withdo_action_ref_array
inwp-includes/class-wp.php
. Probably a 3rd party (plugin/theme) is callingdo_action('wp'...
.Note: a quick way to rule out a misbehaving plugin is put your testing code in your theme’s functions.php, rename your plugins directory to something like
plugins.temp
and access your front-end. Then, rename your plugins directory back toplugins
.