• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer
WordPress core a2z

WordPress core a2z

WordPress core only

  • Home
  • Plugins
  • Blocks
  • Shortcodes
  • APIs
  • Classes
  • Files
  • Hooks
  • Sitemap
  • Blog
Home / APIs / wp_link_pages() – The formatted output of a list of pages.

You appear to be a bot. Output may be restricted

Description

The formatted output of a list of pages.

Displays page links for paginated posts (i.e. including the <!--nextpage--> Quicktag one or more times). This tag must be within The Loop.

Usage

$string = wp_link_pages( $args );

Parameters

$args
( string|array ) optional – { Optional. Array or string of default arguments.
$before
( string ) optional – HTML or text to prepend to each link. Default is `<p> Pages:`.
$after
( string ) optional – HTML or text to append to each link. Default is `</p>`.
$link_before
( string ) optional – HTML or text to prepend to each link, inside the <a> tag. Also prepended to the current item, which is not linked. Default empty.
$link_after
( string ) optional – HTML or text to append to each Pages link inside the <a> tag. Also appended to the current item, which is not linked. Default empty.
$aria_current
( string ) optional – The value for the aria-current attribute. Possible values are 'page', 'step', 'location', 'date', 'time', 'true', 'false'. Default is 'page'.
$next_or_number
( string ) optional – Indicates whether page numbers should be used. Valid values are number and next. Default is 'number'.
$separator
( string ) optional – Text between pagination links. Default is ' '.
$nextpagelink
( string ) optional – Link text for the next page link, if available. Default is 'Next Page'.
$previouspagelink
( string ) optional – Link text for the previous page link, if available. Default is 'Previous Page'.
$pagelink
( string ) optional – Format string for page numbers. The % in the parameter string will be replaced with the page number, so 'Page %' generates "Page 1", "Page 2", etc. Defaults to '%', just the page number.
$echo
( int|bool ) optional – Whether to echo or not. Accepts 1|true or 0|false. Default 1|true. }

Returns

string Formatted output in HTML.

Source

File name: wordpress/wp-includes/post-template.php
Lines:

1 to 92 of 92
function wp_link_pages( $args = '' ) {
  global $page, $numpages, $multipage, $more;

  $defaults = array(
    'before'           => '<p class="post-nav-links">' . __( 'Pages:' ),
    'after'            => '</p>',
    'link_before'      => '',
    'link_after'       => '',
    'aria_current'     => 'page',
    'next_or_number'   => 'number',
    'separator'        => ' ',
    'nextpagelink'     => __( 'Next page' ),
    'previouspagelink' => __( 'Previous page' ),
    'pagelink'         => '%',
    'echo'             => 1,
  );

  $parsed_args = wp_parse_args( $args, $defaults );

  
/**
 * Filters the arguments used in retrieving page links for paginated posts.
 *
 * @since 3.0.0
 *
 * @param array $parsed_args An array of arguments for page links for paginated posts.
 */
  $parsed_args = apply_filters( 'wp_link_pages_args', $parsed_args );

  $output = '';
  if ( $multipage ) {
    if ( 'number' === $parsed_args['next_or_number'] ) {
      $output .= $parsed_args['before'];
      for ( $i = 1; $i <= $numpages; $i++ ) {
        $link = $parsed_args['link_before'] . str_replace( '%', $i, $parsed_args['pagelink'] ) . $parsed_args['link_after'];
        if ( $i != $page || ! $more && 1 == $page ) {
          $link = _wp_link_page( $i ) . $link . '</a>';
        } elseif ( $i === $page ) {
          $link = '<span class="post-page-numbers current" aria-current="' . esc_attr( $parsed_args['aria_current'] ) . '">' . $link . '</span>';
        }
        
/**
 * Filters the HTML output of individual page number links.
 *
 * @since 3.6.0
 *
 * @param string $link The page number HTML output.
 * @param int    $i    Page number for paginated posts' page links.
 */
        $link = apply_filters( 'wp_link_pages_link', $link, $i );

        // Use the custom links separator beginning with the second link.
        $output .= ( 1 === $i ) ? ' ' : $parsed_args['separator'];
        $output .= $link;
      }
      $output .= $parsed_args['after'];
    } elseif ( $more ) {
      $output .= $parsed_args['before'];
      $prev    = $page - 1;
      if ( $prev > 0 ) {
        $link = _wp_link_page( $prev ) . $parsed_args['link_before'] . $parsed_args['previouspagelink'] . $parsed_args['link_after'] . '</a>';

        
/** This filter is documented in wp-includes/post-template.php */
        $output .= apply_filters( 'wp_link_pages_link', $link, $prev );
      }
      $next = $page + 1;
      if ( $next <= $numpages ) {
        if ( $prev ) {
          $output .= $parsed_args['separator'];
        }
        $link = _wp_link_page( $next ) . $parsed_args['link_before'] . $parsed_args['nextpagelink'] . $parsed_args['link_after'] . '</a>';

        
/** This filter is documented in wp-includes/post-template.php */
        $output .= apply_filters( 'wp_link_pages_link', $link, $next );
      }
      $output .= $parsed_args['after'];
    }
  }

  
/**
 * Filters the HTML output of page links for paginated posts.
 *
 * @since 3.6.0
 *
 * @param string $output HTML output of paginated posts' page links.
 * @param array  $args   An array of arguments.
 */
  $html = apply_filters( 'wp_link_pages', $output, $args );

  if ( $parsed_args['echo'] ) {
    echo $html;
  }
  return $html;
}
 

 View on GitHub View on Trac

Published: 25th November 2019 | Last updated: 21st August 2020

Primary Sidebar

Information

Function name: wp_link_pages
Plugin ref: WordPress
Version: 5.6.2
Sourcefile: wp-includes/post-template.php
File ref: wp-includes/post-template.php
Deprecated?: No
API Letters: L,P,W

Footer

WP-a2z
WordPress core a2z
WordPress core only
WordPress 5.6.2
WordPress a2z
WordPress core a2z
Genesis Theme Framework a2z
Jetpack a2z
WordPress develop tests
Easy Digital Downloads a2z
WooCommerce a2z
Yoast SEO a2z
WordPress Blocks

Site:  core.wp-a2z.org
© Copyright WP-a2z 2014-2021. All rights reserved.


Website designed and developed by Herb Miller
Proudly powered by WordPress and oik plugins

  • Home
  • Blog
  • Sitemap
  • Sites