WordPress wp_link_pages() Function

Beginner
6 min read
Updated: Nov 2026
3 examples
Prints page links

Definition

In WordPress, wp_link_pages() prints page links for a long post that you split into several pages. You split a post by adding the Page Break block (or the <!--nextpage--> tag).

Place it after the_content() so readers can move between the pages of one post.

Syntax

A few ways to call wp_link_pages().

WordPress
<?php
the_content();
wp_link_pages();
CallWhat it does
wp_link_pages()Print page numbers with the default markup.
wp_link_pages( array( 'before' => '<nav>', 'after' => '</nav>' ) )Wrap the links in your own tags.
wp_link_pages( array( 'next_or_number' => 'next' ) )Show Previous and Next links.
wp_link_pages( array( 'echo' => 0 ) )Return the links instead of printing.

It takes one array of options. Common options are before, after, separator, next_or_number, and echo.

Full declaration
WordPress
wp_link_pages( string|array $args = '' ): string

Parameters

ParameterDescription
beforestring. HTML before the links. Default is <p>Pages:.
afterstring. HTML after the links. Default is </p>.
link_beforestring. HTML before each link text. Default is empty.
link_afterstring. HTML after each link text. Default is empty.
separatorstring. Text between links. Default is a space.
next_or_numberstring. number for page numbers, or next for Previous and Next links. Default is number.
nextpagelinkstring. Text of the next link. Default is Next page.
previouspagelinkstring. Text of the previous link. Default is Previous page.
pagelinkstring. Link text format. % is replaced by the page number. Default is %.
echoint|bool. 1 prints. 0 returns. Default is 1.

Return Value

Return ValueDescription
stringThe links HTML. It is also printed when echo is on.

WordPress Examples

Three short examples. Each one shows the code and what it prints.

Example 1 — Page numbers under the content

Add the default page links.

WordPress
<?php
the_content();
wp_link_pages();

How It Works

  1. The sample post has three pages.
  2. The current page is a span, and the others are links.
  3. The default text is Pages:.

Example 2 — Previous and Next links

Use next_or_number to show Previous and Next.

WordPress
<?php
wp_link_pages( array(
  'before'           => '<div class="page-links">',
  'after'            => '</div>',
  'next_or_number'   => 'next',
  'previouspagelink' => '&laquo; Back',
  'nextpagelink'     => 'Next &raquo;',
) );

How It Works

  1. next_or_number set to next shows two links.
  2. We changed the text of both.
  3. This sample is page 2 of the post.

Example 3 — Return the links

Set echo to 0 to store the HTML.

WordPress
<?php
$links = wp_link_pages( array( 'echo' => 0 ) );
if ( $links ) {
  echo '<nav class="post-pages">' . $links . '</nav>';
}

How It Works

  1. echo set to 0 returns the HTML.
  2. The if skips posts that have only one page.
  3. You can add your own wrapper.

Frequently Asked Questions

It prints page links for a post that is split into several pages.
Add the Page Break block, or type <!--nextpage--> in the code editor, where you want a new page to start.
The post may have only one page, or the function is not placed after the_content() in the Loop.
Pass array( 'next_or_number' => 'next' ).
Pass array( 'echo' => 0 ).

Browse all post functions

Open the functions index for simple guides with examples and FAQs.

Post Functions Index →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

13 people found this page helpful