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
    CSS @supports

    Feature detection via JavaScript is a client side best practice and for all the right reasons, but unfortunately that same functionality hasn't been available within CSS.  What we end up doing is repeating the same properties multiple times with each browser prefix.  Yuck.  Another thing we...

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

Incredible Demos

  • By
    Cross Browser CSS Box Shadows

    Box shadows have been used on the web for quite a while, but they weren't created with CSS -- we needed to utilize some Photoshop game to create them.  For someone with no design talent, a.k.a me, the need to use Photoshop sucked.  Just because we...

  • By
    dwClickable:  Entire Block Clickable Using MooTools 1.2

    I recently received an email from a reader who was really impressed with Block Clickable, a jQuery script that took the link within a list item and made the entire list item clickable. I thought it was a neat script so I...

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!