Skip to content

Instantly share code, notes, and snippets.

@maheshwaghmare
Last active September 18, 2020 20:48
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save maheshwaghmare/274d629a46a03dfd5b3214080cedbd76 to your computer and use it in GitHub Desktop.
Save maheshwaghmare/274d629a46a03dfd5b3214080cedbd76 to your computer and use it in GitHub Desktop.
WordPress - Show the (next and previous) navigation for post, page and custom post types (CPT). Use `[show_post_navigation]`
<?php
/**
* Show the (next and previous) navigation for post, page and custom post types (CPT).
*
* @example [show_post_navigation]
*
* @todo Change the `prefix_` and with your own unique prefix.
*
* @since 1.0.0
*/
if( ! function_exists( 'prefix_post_navigation' ) ) :
function prefix_post_navigation( $atts, $content ) {
if( ! is_singular( ) ) {
return '';
}
$post_obj = get_post_type_object( get_post_type() );
$next_text = sprintf(
'Next %s &rarr;',
$post_obj->labels->singular_name
);
$prev_text = sprintf(
'&larr; Previous %s',
$post_obj->labels->singular_name
);
return get_the_post_navigation( array(
'next_text' => $next_text,
'prev_text' => $prev_text,
) );
}
add_shortcode( 'show_post_navigation', 'prefix_post_navigation' );
endif;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment