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 get Woocommerce order product info
- Inserting choice in database table
- How to retrieve a value from get_posts()? [closed]
- Change Password Hint
- Woocommerce auto cancel On-Hold after X days
- Handling error states with admin_post
- How to update single value in multi dimensional Post Meta?
- Why does “get_option” pull in the older value in options.php, rather than the newer value, on submission of a form?
- Enqueue less file not working in child theme?
- Integrating PHP into Javascript to display map markers with Google API
- Passing array in add_option()
- Excerpt unwanted text “”
- WordPress Custom Content and Taxonomy’s Archives
- what is the best practice to add new field to an api route
- How to get next image with this code from same post?
- WordPress returns “The link you followed has expired” error page whenever I add a new site, add a user etc
- how to save selected option in variable for rest api category filter
- iframe does not store session/cookie when refresh parent
- Frontend in WP , backend in Laravel. Some level of integration needed
- Trying to store submenu items to render out after main menu
- Alter required message using comment form api
- WordPress function and string as variable?
- Theme’s Options Page included with require_once *.php in functions.php not visible anymore
- Get access to variable from previous pageview, excluding ajax-calls
- Permission callback to check if user has application password
- Hide posts if user is added to it WP_query
- Set default Database Storage Engine when creating tables with plugins?
- Plugin can’t write to database even though permissions appear correct?
- How to deal with a GET variable of ‘name’?
- I can’t set image ad fatured programatically
- Replace a single variable with add_filter
- I am having issue in divi woocomerce checkout module. (DIVI theme)
- meta_query search names when they have middle initials
- Not work function add width and height at save post
- Exclude multiple authors by ID – IF condition
- Trying to use a variable to set image width
- What is the correct way to search 3 custom fields only in WordPress?
- How to change order inside foreach using wp_enqueue_script?
- Redirect user to a custom url after logged in
- Adding extra data to shortcode attributes and pass it to JS with wp_localize_script
- Related Posts: if there is no category use tags
- How to get all users by user_login as a json_encode array?
- defined (‘ABSPATH’) false after AJAX post to other PHP-file
- Determine if a page has been saved yet and has an ID using PHP?
- Some links broken after updating WordPress version
- Can’t get data from audio media
- Echo multiple tasks if a common function exists
- Saving Post redirects to 404 page when php $_GET variable in post body
- category & sub category order issues in wordpress
- Why not showing all post by default in my jquery filter
- how to convert wordpress query to pdo query
- Add topbar to static html page
- Execute multiple PHP Snippets causes error?
- Social Sharing Buttons in Recent Articles List
- Add Woocommerce Customers link to custom admin menu
- Preventing script injections in HTML form
- How to add a php package to an existing wordpress website