Using WordPress ‘link_pages()’ PHP function

The link_pages() WordPress PHP function prints a list of pages based on the given arguments.

Usage

link_pages($before, $after, $next_or_number, $nextpagelink, $previouspagelink, $pagelink, $more_file);

Parameters

  • $before (string) – Optional. The content before the page links. Default: <br />
  • $after (string) – Optional. The content after the page links. Default: <br />
  • $next_or_number (string) – Optional. Whether to display next/previous page links or page numbers. Default: ‘number’
  • $nextpagelink (string) – Optional. The text for the “next page” link. Default: ‘next page’
  • $previouspagelink (string) – Optional. The text for the “previous page” link. Default: ‘previous page’
  • $pagelink (string) – Optional. The format of the page number links. Default: ‘%’
  • $more_file (string) – Optional. The file to open when the “more” link is clicked. Default: ”

More information

See WordPress Developer Resources: link_pages

Examples

In this example, we will display a simple list of page links using the default settings.

// In your theme's single.php or page.php file, add the following code
link_pages();

Customize before and after content

This example customizes the content before and after the page links.

link_pages('<p>Pages: ', '</p>');

This example shows how to display next and previous page links instead of page numbers.

link_pages('<p>', '</p>', 'next');

This example customizes the text for next and previous page links.

link_pages('<p>', '</p>', 'next', 'Next &raquo;', '&laquo; Previous');

This example customizes the format of the page number links.

link_pages('<p>', '</p>', 'number', '', '', '[%]');