Functions
Next Page: next_page_ID($id)
Previous Page: previous_page_ID($id)
$id
: The ID of the page you're trying to get the next or previous page for.
Examples
$next_ID = next_page_ID('41);
$previous_ID = previous_page_ID('41);
$next_url = get_permalink($next_ID);
echo '<a href="' . $next_url . '">Next Page</a>';
Hi could you please help me. I have tried to use a code to do next and previous with shortcodes in function but the ID order of page is not followed...
Could you please tell me how to
or
Thank you so much for your help. I think it because I used Elementor in wordpress that it messed things up :(
`
add_shortcode( 'prev', 'prev_shortcode' );
add_shortcode( 'next', 'next_shortcode' );
function next_shortcode($atts) {
global $post;
ob_start();
next_post_link( '
', '%title ' . _x( '→', 'Previous post link', 'morphology' ) . '',
true);
$result = ob_get_contents();
ob_end_clean();
return $result;
}
function prev_shortcode($atts) {
global $post;
ob_start();
previous_post_link( '
', '%title ' . _x( '→', 'Previous post link', 'morphology' ) . '',
true );
$result = ob_get_contents();
ob_end_clean();
return $result;
}``