I want to create a pagenation using wp_link_pages that looks like this

Previous 3 of 20 Next

How can this be achieved?

I am using this function btw https://codex.wordpress.org/Function_Reference/wp_link_pages

1 Answer 1


I don't see a way to do this with just the standard arguments but you can do it with a filter:

function link_hack_wpse_($output,$args) {
  global $page, $numpages;
  $xofy = $page.' of '.$numpages;
  if (1 == $page) {
    $output = str_replace($args['after']," $xofy{$args['after']}",$output);
  } elseif ($page == $numpages) {
    $output = str_replace($args['before'],"{$args['before']}$xofy ",$output);
  } else {
    $output = str_replace('</a><a',"</a> $xofy <a",$output);
  return $output;

$args = array(
  'before'           => '<p>',
  'after'            => '</p>',
  'next_or_number'   => 'next',
  'separator'        => '',
  'nextpagelink'     => __( 'Next' ),
  'previouspagelink' => __( 'Previous' ),
  'pagelink'         => '%',
  'echo'             => 1

wp_link_pages( $args );

I should note that this is very dependent upon the $args settings. It is not going to be portable without modification.

  • Thanks! I was just starting to look towards this direction. This work's and does just what I need. I also had some code to replace the wp_link_pages with my own custom function which also worked nicely. Thanks for the code!
    – Dan
    Commented Jun 22, 2015 at 12:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.