• Hello,
    I use the page break block in Gutenberg in order to have several pages for a post, instead of one long post.
    That creates numbers for all of the pages under the text area.
    I want instead of the page numbers – to have “next page” or “previous page” like in this picture – https://www.linkpicture.com/q/prev-next.jpg
    (translation for the picture – on the top it says “pages – 1, 2, 3” etc. and on the bottom it says “previous – page 3” “next – page 5”)

    How can I do that?

    (I use the Astra theme)

    Thanks ??

Viewing 3 replies - 1 through 3 (of 3 total)
  • Moderator bcworkz

    (@bcworkz)

    You could add the following filter code:

    add_filter('wp_link_pages_args', 'bcw_next_prev_page_links');
    function bcw_next_prev_page_links( $args ) {
    	$replace = array_merge( $args, array (
    		'before'            => '<div class="page-links">',
    		'after'             => '</div>',
    		'link_before'       => '<span class="page-link">',
    		'link_after'        => '</span>',
    		'next_or_number'    => 'next',
    		'separator'         => ' | ',
    		'nextpagelink'      => 'Next &raquo;',
    		'previouspagelink'  => '&laquo; Previous',
    	));
    	return $replace;
    }

    You may alter anything within single quotes that are right of => as desired, except for 'next', that’s what suppresses the page numbers. The first 4 array items are default HTML for Astra. If you alter those, you may also need corresponding CSS styling.

    This code could go in the theme’s functions.php file, but it’ll get overwritten during theme updates. If you already use a child theme, it should go in the child’s functions.php. If you don’t have a child theme, you could create one, but it’s actually easier to create a basic plugin. Filter and action hooks can go in a plugin, but if you will be customizing templates, creating a child theme is the way to go.

    Thread Starter avscor

    (@avscor)

    Thank you very much for the help!!
    I want to try this, but I have changed my theme today to Generatepress because I needed a lighter theme…

    Will this code work for Generatepress as well?
    And if so – should I use it with the same Instructions?

    Thank you! ??

    Moderator bcworkz

    (@bcworkz)

    My suggestion should work with any theme that calls wp_link_pages() on their single post template. I think most do. GeneratePress certainly does. It even uses the very same before/after HTML, so its default CSS will still be applied. GeneratePress does not specify before/after link HTML but I don’t think the added span HTML will be a problem. You can change those to empty strings to better match normal GeneratePress parameters.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘How to put prev/next instead of page numbers?’ is closed to new replies.