WordPress.org

Ready to get started?Download WordPress

Codex

Attention Interested in functions, hooks, classes, or methods? Check out the new WordPress Code Reference!

Function Reference/wp link pages

Description

Displays page-links for paginated posts (i.e. includes the <!--nextpage--> Quicktag one or more times). This works in much the same way as link_pages() (deprecated), the difference being that arguments are given in query string format. This tag must be within The_Loop.

Usage

 <?php wp_link_pages$args ); ?> 

Default Usage

<?php
 	$defaults = array(
		'before'           => '<p>' . __( 'Pages:' ),
		'after'            => '</p>',
		'link_before'      => '',
		'link_after'       => '',
		'next_or_number'   => 'number',
		'separator'        => ' ',
		'nextpagelink'     => __( 'Next page' ),
		'previouspagelink' => __( 'Previous page' ),
		'pagelink'         => '%',
		'echo'             => 1
	);
 ?>

Parameters

before 
(string) Text to put before all the links. Defaults to <p>Pages:.
after 
(string) Text to put after all the links. Defaults to </p>.
link_before 
(string) Text that goes before the text of the link. Defaults to (blank). Version 2.7 or later required.
link_after 
(string) Text that goes after the text of the link. Defaults to (blank). Version 2.7 or later required.
next_or_number 
(string) Indicates whether page numbers should be used. Valid values are:
  • number (Default)
  • next (Valid in WordPress 1.5 or after)
separator 
(string) Text to be used between page numbers (if applicable). Defaults to a single breakable space. (Valid in WordPress 3.6 or after)
nextpagelink 
(string) Text for link to next page. Defaults to Next page. (Valid in WordPress 1.5 or after)
previouspagelink
(string) Text for link to previous page. Defaults to Previous page. (Valid in WordPress 1.5 or after)
pagelink 
(string) Format string for page numbers.  % in the string will be replaced with the number, so Page % would generate "Page 1", "Page 2", etc. Defaults to %.
echo 
(boolean) Toggles whether to echo or return the result. The default is true. Valid values:
  • 1 (True) - Default
  • 0 (False)

Return Values

(mixed) 
If $echo is set to true (default), returns NULL and echos the content. If $echo is set to false, returns formatted output in HTML.

Examples

Default Usage

Displays page-links by default with paragraph tags before and after, using Next page and Previous page, listing them with page numbers as Page 1, Page 2 and so on.

<?php wp_link_pages(); ?>

Page-links in Paragraph Tags

Displays page-links wrapped in paragraph tags.

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

Page-links in DIV

Displays page-links in DIV for CSS reference as <div id="page-links">.

<?php wp_link_pages('before=<div id="page-links">&after=</div>'); ?>

Adding wp_link_pages in content.php

This code snippet can be added directly to your content.php or single.php file in the position you want your pagination to display.

<?php wp_link_pages( array(
	'before'      => '<div class="page-links"><span class="page-links-title">' . __( 'Pages:', 'twentyfourteen' ) . '</span>',
	'after'       => '</div>',
	'link_before' => '<span>',
	'link_after'  => '</span>',
	) );
?>

Changelog

Since: 0.71

Source File

wp_link_pages() is located in wp-includes/post-template.php.

Related

See also index of Function Reference and index of Template Tags.