EN / ZH
Paginating Single Posts in WordPress Without Plugins

I remember a long time ago when I was tinkering with a design tutorial website called “Visual Sky City,” which was also built on WordPress. Being a design tutorial site, articles naturally contained tons of images. A single article could grow terrifyingly long and load very slowly, making a pagination feature an urgent necessity!

I tried several tutorials found online, and most of them leveraged WordPress’s built-in hidden post content pagination feature.

Here’s how to enable WordPress’s hidden post content pagination feature (I’ve only tested this on WordPress 3.1.1):

  1. Find wp-includes/js/quicktags.js and locate the following code:
edButtons[edButtons.length]=new edButton("ed_more","more","<!–more–>","","t",-1);

Add the following code right after it:

edButtons[edButtons.length]=new edButton("ed_next","page","<!–nextpage–>","","p",-1);

Note: It’s “ed_next”, not “ed_netx”. It’s “–nextpage–”, not “–netxpage–” — many tutorials online have these typos.

  1. Still in wp-includes/js/quicktags.js, find this code:
j.Buttons[j.Buttons.length]=new edButton(a+"_more","more","<!–more–>","","t",-1);

Add the following after it:

j.Buttons[j.Buttons.length]=new edButton(a+"_next","page","<!–nextpage–>","","p",-1);

Save wp-includes/js/quicktags.js.

  1. Find wp-includes/js/quicktags.dev.js and locate this code:
/* edButtons[edButtons.length] = new edButton('ed_next' ,'page' ,'<!–nextpage–>' ," ,'p' ,-1 ); */

Remove the comment markers so it becomes:

edButtons[edButtons.length] = new edButton('ed_next' ,'page' ,'<!–nextpage–>' ," ,'p' ,-1 );
  1. Find wp-admin/includes/post.php and locate this code:
'link', 'unlink', 'wp_more',

Add the following after it:

'wp_page',

The hidden post content pagination feature in WordPress 3.1.1 is now enabled. As shown below: (the icon looks similar to the “more” icon)

Next, we need to add the pagination function to single.php in your current theme directory. Find this code:

<?php the_content(); ?>

Add the pagination function below it:

<?php wp_link_pages('before=&after=&next_or_number=number&pagelink=Page %'); ?>

Now you can create a long article to test the effect. If you know CSS, you can also style the pagination. For details on the wp_link_pages function, check the WordPress documentation: http://codex.wordpress.org/Template_Tags/wp_link_pages

This pagination feature isn’t very SEO-friendly, so we need to make some improvements. This method is based on: http://wordpress.org.cn/thread-61875-1-1.html

  1. Find header.php in your current theme directory and add the following code before </head>:
<?php if ( is_singular() ){ ?> <link rel="canonical" href="<?php the_permalink(); ?>" /> <?php } ?>
  1. In header.php, after the code that outputs the description meta tag, add:
<?php if (get_query_var('paged')) { //check if it's the homepage echo 'Page '; echo get_query_var('paged'); //page number }?>

This method may have some issues — I haven’t noticed any difference after implementing it.

  1. To prevent feed output from being paginated, find wp-includes/query.php and locate this code:
if ( strpos( $content, '<!–nextpage–>' ) ) {

Change it to:

if ( strpos( $content, '<!–nextpage–>' ) && (!is_feed()) ) {

The modifications are essentially complete. If you have any questions, feel free to raise them for discussion.