Example 1 — Page numbers under the content
Add the default page links.
<?php
the_content();
wp_link_pages(); How It Works
- The sample post has three pages.
- The current page is a
span, and the others are links. - The default text is
Pages:.

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.
A few ways to call wp_link_pages().
<?php
the_content();
wp_link_pages(); | Call | What 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.
wp_link_pages( string|array $args = '' ): string | Parameter | Description |
|---|---|
before | string. HTML before the links. Default is <p>Pages:. |
after | string. HTML after the links. Default is </p>. |
link_before | string. HTML before each link text. Default is empty. |
link_after | string. HTML after each link text. Default is empty. |
separator | string. Text between links. Default is a space. |
next_or_number | string. number for page numbers, or next for Previous and Next links. Default is number. |
nextpagelink | string. Text of the next link. Default is Next page. |
previouspagelink | string. Text of the previous link. Default is Previous page. |
pagelink | string. Link text format. % is replaced by the page number. Default is %. |
echo | int|bool. 1 prints. 0 returns. Default is 1. |
| Return Value | Description |
|---|---|
| string | The links HTML. It is also printed when echo is on. |
Three short examples. Each one shows the code and what it prints.
Add the default page links.
<?php
the_content();
wp_link_pages(); span, and the others are links.Pages:.Use next_or_number to show Previous and Next.
<?php
wp_link_pages( array(
'before' => '<div class="page-links">',
'after' => '</div>',
'next_or_number' => 'next',
'previouspagelink' => '« Back',
'nextpagelink' => 'Next »',
) ); next_or_number set to next shows two links.Set echo to 0 to store the HTML.
<?php
$links = wp_link_pages( array( 'echo' => 0 ) );
if ( $links ) {
echo '<nav class="post-pages">' . $links . '</nav>';
} echo set to 0 returns the HTML.if skips posts that have only one page.Open the functions index for simple guides with examples and FAQs.
13 people found this page helpful