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
    Introducing MooTools Templated

    One major problem with creating UI components with the MooTools JavaScript framework is that there isn't a great way of allowing customization of template and ease of node creation. As of today, there are two ways of creating: new Element Madness The first way to create UI-driven...

  • By
    Write Better JavaScript with Promises

    You've probably heard the talk around the water cooler about how promises are the future. All of the cool kids are using them, but you don't see what makes them so special. Can't you just use a callback? What's the big deal? In this article, we'll...

Incredible Demos

  • By
    Animated AJAX Record Deletion Using Dojo

    I'm a huge fan of WordPress' method of individual article deletion. You click the delete link, the menu item animates red, and the item disappears. Here's how to achieve that functionality with Dojo JavaScript. The PHP - Content & Header The following snippet goes at the...

  • By
    PHP IMDB Scraper

    It's been quite a while since I've written a PHP grabber and the itch finally got to me. This time the victim is the International Movie Database, otherwise known as IMDB. IMDB has info on every movie ever made (or so it seems). Their...

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!