2

I am referencing the WP codex here: https://codex.wordpress.org/Styling_Page-Links but cannot find a way to customize the post URL for page break ( ) feature. For exmaple: instead of the traditional .../post/2/ I would like for it to be called .../post/page2/

here is what I currently have in my themes functions.php file

//Display Number & Next/Previous Links with wp_link_pages
add_filter('wp_link_pages_args','add_next_and_number');

function add_next_and_number($args){
    if($args['next_or_number'] == 'next_and_number'){
        global $page, $numpages, $multipage, $more, $pagenow;
        $args['next_or_number'] = 'number';
        $prev = '';
        $next = '';
        if ( $multipage ) {
            if ( $more ) {
                $i = $page - 1;
                if ( $i && $more ) {
                    $prev .= _wp_link_page($i);
                    $prev .= $args['link_before']. $args['previouspagelink'] . $args['link_after'] . '</a>';
                }
                $i = $page + 1;
                if ( $i <= $numpages && $more ) {
                    $next .= _wp_link_page($i);
                    $next .= $args['link_before']. $args['nextpagelink'] . $args['link_after'] . '</a>';
                }
            }
        }
        $args['before'] = $args['before'].$prev;
        $args['after'] = $next.$args['after'];    
    }
    return $args;
}

add_filter ('the_content', 'pagination_after_post',1);
function pagination_after_post($content) {
   if(is_single()) {
      $content.= '<nav class="pagination">' . 
      wp_link_pages(array(
        'before' => '' . __('Pages:'),
        'after' => '',
        'next_or_number' => 'next_and_number',
        'nextpagelink' => '<li>'.__('Next'), '</li>',
        'previouspagelink' => '<li>'.__('Previous'),'</li>',
        'pagelink' => '%',
        'echo' => 0 )
    );
       '</nav>';
   }
   return $content;
}

Can the URL be changed via the functions.php? Or does this have to do with .htaccess file on apache?

  • 1
    Any answer will probably involve rewrite rule changes as well as changes to the pagination functions, it definitely isn't a trivial ask though if you thought it was a small quick/easy change – Tom J Nowell Jul 18 '18 at 16:55
  • thanks - I didn't think it was small quick/easy change - trying to sway the decision away from doing this. Frankly I don't see many folks using the page break function much these days. – Jay Caetano Jul 18 '18 at 21:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.