Prevent WordPress from Loading “Next” Pages
I've been working to make this blog more performant by lazy loading everything I can think of, placing CSS and JavaScript into the HTML, and using data URIs; the common theme in these is reducing the number of requests on each page. One request I noticed (and hadn't anticipated) coming from WordPress looked like this:
<link rel="next" href="https://davidwalsh.name/page/2/" />
Wordpress was essentially preloading the second listing page of my blog, assuming that people would click a link to page 2. When looking at my blog stats, that was very rarely the case (probably because I list 15 items on the homepage, which is a lot), so why bother sending the request at all? This bit of WordPress magic will prevent that LINK element from being used:
// ... in functions.php... // Prevent unwanted next and prev link downloads if(function_exists('remove_action')) { remove_action('wp_head', 'start_post_rel_link', 10, 0); remove_action('wp_head', 'adjacent_posts_rel_link', 10, 0); }
There are two function calls removed -- one to prevent the tag from being used on the homepage/listing pages, and the other used on single blog posts. Of course removing this call isn't for everyone but since I'm trying to micro-optimize the site, I thought I'd cut it out.
Google indicates a couple of reasons why the links are relevant to their search indices at http://googlewebmastercentral.blogspot.ch/2011/09/pagination-with-relnext-and-relprev.html.
I didn’t know that WordPress function neither. Good to know!
These actions are now deprecated. Use:
instead!