Prevent WordPress from Loading “Next” Pages

By  on  

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.

Recent Features

  • By
    Facebook Open Graph META Tags

    It's no secret that Facebook has become a major traffic driver for all types of websites.  Nowadays even large corporations steer consumers toward their Facebook pages instead of the corporate websites directly.  And of course there are Facebook "Like" and "Recommend" widgets on every website.  One...

  • By
    Create a CSS Flipping Animation

    CSS animations are a lot of fun; the beauty of them is that through many simple properties, you can create anything from an elegant fade in to a WTF-Pixar-would-be-proud effect. One CSS effect somewhere in between is the CSS flip effect, whereby there's...

Incredible Demos

Discussion

  1. 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.

  2. I didn’t know that WordPress function neither. Good to know!

  3. These actions are now deprecated. Use:

    remove_action('wp_head', 'adjacent_posts_rel_link', 10, 0);

    instead!

Wrap your code in <pre class="{language}"></pre> tags, link to a GitHub gist, JSFiddle fiddle, or CodePen pen to embed!