WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

In my case I've got to create articles where each article has a custom, unchanging "header" part far too rich for the title and the excerpt (it's to contain image, media etc), and then a few different pages of content. I've decided to do this using <!--nextpage--> to keep it lightweight and easy for whoever will create the pages - treat the first page as the unchanging header and attach page 2, 3, 4 under a fixed set of links - an custom menu generated in that category, replacing standard pagination "Page 1 2 3 4" links.

In order to do that, I'll have to call the_content() twice; once for page 1, and once for whichever page is chosen through the dedicated menu. Except I have no clue how to make the_content() extract n-th page, other than through appending /n/ to the URL.

Is there some variable, function, plugin, modification to the code that lets me extract a specific page of paginated post?

share|improve this question
I think it would be better to use a separate metabox with a visual editor for the header. – toscho Jul 15 '13 at 17:15
up vote 1 down vote accepted

nextpage pagination is a bit odd. You will have to parse the post content. This should do it.

function get_nth_page($n=0,$content='') {
  if (empty($content)) {
    global $post;
    $content = $post->post_content;
  if (empty($content)) {
    return false;
  $content = str_replace("\n<!--nextpage-->\n", '<!--nextpage-->', $content);
  $content = str_replace("\n<!--nextpage-->", '<!--nextpage-->', $content);
  $content = str_replace("<!--nextpage-->\n", '<!--nextpage-->', $content);
  $pages = explode('<!--nextpage-->', $content);
  if (isset($pages[$n])) {
    return $pages[$n];

You can pass $content explicitly or it will try to grab the global $post variable.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.