I think you should use wp_link_pages function, it’s was built for that purpose.
$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
);
wp_link_pages( $defaults );
You can refer to the codex page to learn more how to use each parameter : https://codex.wordpress.org/Function_Reference/wp_link_pages
Related Posts:
- Mega Menu Walker
- Displaying Logged-In User Name in WordPress Menu
- How can I limit the length of the previous/next posts in my WordPress Theme?
- Logout and redirect using the WP Menu
- Second Navigation inside header
- How can I add a custom class to only nav sub-menu > li > a items in WordPress?
- items_wrap not working
- Style wp_page_menu() items
- Change Navigation Bar based on logged in or not
- Multiple WordPress Menus that will only display all pages
- Hide Hamburger Menu On Specific Page (Front Page/Home Page)
- Menu Limitations
- Reordering Buddy Press profile navigation [closed]
- How to remove role=”navigation” from all nav elements?
- How to show all pages in blog navigation?
- Custom Walker_Nav_Menu issue with variables on PHP 7.3
- Help with Sub and Sub-Sub Navigation
- Detecting classes, adding widgets, and adding divs in with a Nav Walker
- How to style one item from main navigation?
- Add login hyperlink to secondary navigation menu
- Help with page nav?
- Menu Custom Data Attributes
- How to Handle Going Backwards in Navigation When Referrer in PHP/JavaScript won’t work?
- How can I get “Previous” and “Next” to show in the navigation besides the links?
- How to modify mobile nav menu text in theme
- Nav-Menu not showing up
- posts_nav_link pulling in multiple post types
- Custom navigation menu with awsAccordion
- Make next post button link to random post
- Why can’t I add a custom image in my navigation?
- Remove the Tag from wp_nav_menu
- Adding a navigation page state to individual blog and portfolio pages
- WordPress navigation wont appear with wp_head
- In PHP how do I make my navigation bar show certain links to admins only?
- I want to show cart items number if any or nothing, simple CART text
- How to set Nav as a default menu in wordpress
- Redirect User when they click Menu Option
- How to create a sub-page of sub-page?
- Add the “.current-menu-item” class to tag?
- Nav Menu Display
- Open WordPress Page from selected option dropdown
- Custom Navigation Bar JSON Syntax Error in JSON at Position 0
- Nav menù doesn’t display selected pages
- How to integrate noimage picture in this code
- Javascript not loading on certain page
- Location of core code for database connection and get_header
- Deleting Certain terms from appearing on the front end as links
- get comment data using comment id
- meta box not display data input in the textarea
- Clickable image link sends people to wrong URL
- wpdb prepare insert table doesn’t work
- Should I use WordPress to skin a database website?
- php include not working in custom page
- How to modify the default feed via a function
- How do I display offsite database info on my wordpress site?
- Styling the second sidebar
- first instantiated SimplePie object cosumes 5mb?
- Adding a line of text to php code
- If ‘editor’ is empty, then
- Different Subdomain changes page content
- Theme not calling Jquery properly
- customize wordpress database error page
- Removing the comment function within wordpress
- Creating Database Table vs. Adding MetaData to Post & User
- Post’s ID pattern?
- Countdown to date function?
- Include text in echoed hyperlink
- How to put a form with php code into a variable or shortcode?
- Utilize Function in Child Theme / Template File
- Add class to DIV depending on page loaded
- Need oop for wordpress theme? [duplicate]
- Display Youtube Time Automate from Key
- Content filter won’t work
- How to retrive the text : No movie by this actor
- Make a database query using WordPress
- Is the 404 page automatically displayed if a loop returns nothing?
- update_post_meta only updating on last loop of foreach
- How to have different header.php based on the user logged in?
- How do I remove a category from a wordpress loop>
- How can i count the post added in relationship field, theme display
- Link blogname and blogdescription to the Options Framework
- Liking a facebook page from wordpress website?
- Isotope Drop Down Categories Filter Function
- First Byte Time (back-end processing)
- How do I define a lookup table that will work across all PHP elements of the template?
- How to keep track of when a vote is cast?
- trouble with page_id & highlighting current page
- Convert the_permalink() function output into string
- Making my first wordpress template
- How to use array in function to get only value I want
- Apply class to every third list item? [duplicate]
- Only show image from custom field when present
- Cinema site, retrive the movies that actor play in
- How to include custom code on a page that’s set to act as homepage?
- retain querystring values when savincustom options in admin
- PHP if statement works in template files, but not header
- How Can I Edit the Registration Code?
- Error while setting role
- Editing a PHP file to include a small text piece on every page
- Get categories names as an array to use it in theme settings