Script to Automatically Advance to the Next Page of a Paginated Post

Hi @matt:

To achieve what you are asking you need to add some code to queue up a Javascript file and then the Javascript file itself.

You can put the code that follows in your theme’s functions.php file. You’ll note it uses is_admin() to avoid loading the Javascript code in your /wp-admin/ console; you should also add a criteria to avoid loaded it except on the pages where you need (however I wasn’t sure how to limit it since your question didn’t explain enough specifics to do so):

add_action('init','action_init_page_auto_advance');
function action_init_page_auto_advance() {
  if (!is_admin()) { // Make this if() limited to just the pages you need.
    $ss_url = get_stylesheet_directory_uri();
    wp_enqueue_script('jquery');
    wp_enqueue_script('page-auto-advance', 
      "{$ss_url}/js/page-auto-advance.js",
      array("jquery")
    );
  }
}

The prior code loads a file called page-auto-advance.js that you’ll place in a subdirectory of your theme named /js/ and here’s that file. Note it assumes you have “next” links on your site in the format of <a rel="next" href="https://wordpress.stackexchange.com/questions/5559/...">...</a>:

jQuery(document).ready(function($){
  var href = $("a[rel="next"]").attr("href");
  if (href!=undefined)
    setTimeout('window.location.href = jQuery("a[rel=\'next\']").attr("href");',5000);
});

The prior Javascript will advance the page every five seconds (5000 = 5 x 1000 milliseconds) if it finds a link with a rel="next" on the page.

One thing to be aware of is you might find that it advances when you don’t want it to but with this code hopefully you’ll have a starting point that will let you fine-tune it.