What would cause the 'wp' action to fire twice per page (but only once per post) in Firefox only?

I’m using add_action( 'wp', 'do_something_once_per_page' ); and, well, it’s not doing it just once but twice. What’s interesting is that within do_something_once_per_page( $wp ){ } I’m globalizing $post and it’s two different posts!

The way I’m noticing this is with add_user_meta(). Essentially I’m using this to track users’ activity within the site. On the ‘wp’ action, I get the global $page and log the ID against the user’s meta.

For every single page load, I’m getting two log entries. One for the correct page, another one for the very next published page (skipping all revisions or other post-types in-between).

Interestingly (is there a clue here?) for posts, only the correct post is recorded – and the action is not invoked a second time.

I’m still surprised that the ‘wp’ action is being invoked twice at all, even more stumped by the fact that it’s grabbing some other page, that has no relationship (in the menu hierarchy) to the current page being queried.

Further, I cannot for the life of me figure out where this “ghost page” is going – it’s certainly not being sent to the browser as far as I can tell. Is there some phantom AJAX call that may be responsible? What about the Admin bar when you’re logged in (I only record logged in user activity, so there’s always an Admin bar).

I can now confirm that this is a Firefox-only issue! What’s up with that? I can’t even begin to fathom how FF is requesting some other page than the link I click on, why only FireFox, and, like, WTF. Probably much less a WP issue than an FF6 issue.

Solutions Collecting From Web of "What would cause the 'wp' action to fire twice per page (but only once per post) in Firefox only?"

Check the source for your page. I’m guessing that your source code includes a <link rel="next"> in the header, as WordPress injects by default, and Firefox is prefetching the “next” page in order to cache it.

Try this to remove that link from your header:

remove_action('wp_head', 'adjacent_posts_rel_link_wp_head');

Found this blog with more details: WordPress rel=”next” and Firefox Prefetching

Check that you it is not prefetching links. Basically, WordPress themes might print a directive that direct modern browsers to download and cache the next page you are likely to see to improve performance. The html ouput looks something like this

<link rel="prefetch" href="http://www.example.com/">

Search for link prefetching on Google to learn more.