Last active
April 22, 2022 09:07
-
-
Save thecodepoetry/093764ea2d0dd6574bba2f4e4071b375 to your computer and use it in GitHub Desktop.
Prev next in reverse order
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function presscore_new_post_navigation( $args = array() ) { | |
if ( ! in_the_loop() ) { | |
return ''; | |
} | |
$defaults = array( | |
'prev_src_text' => __( 'Previous post:', 'the7mk2' ), | |
'next_src_text' => __( 'Next post:', 'the7mk2' ), | |
'in_same_term' => false, | |
'excluded_terms' => '', | |
'taxonomy' => 'category', | |
'screen_reader_text' => __( 'Post navigation', 'the7mk2' ), | |
); | |
$args = wp_parse_args( $args, $defaults ); | |
$config = presscore_config(); | |
$output = ''; | |
if ( $config->get( 'post.navigation.arrows.enabled' ) ) { | |
$prev_text = '<i class="icomoon-the7-font-the7-arrow-29-3" aria-hidden="true"></i>' . | |
'<span class="meta-nav" aria-hidden="true">' . __( 'Previous', 'the7mk2' ) . '</span>' . | |
'<span class="screen-reader-text">' . esc_html( $args['prev_src_text'] ) . '</span>' . | |
'<span class="post-title h4-size">%title</span>'; | |
// We use opposite order. | |
$prev_link = get_next_post_link( | |
'%link', | |
$prev_text, | |
$args['in_same_term'], | |
$args['excluded_terms'], | |
$args['taxonomy'] | |
); | |
$prev_link = str_replace( '<a', '<a class="nav-previous"', $prev_link ); | |
if ( ! $prev_link ) { | |
$prev_link = '<span class="nav-previous disabled"></span>'; | |
} | |
$output .= $prev_link; | |
} | |
if ( $config->get( 'post.navigation.back_button.enabled' ) ) { | |
$output .= presscore_get_post_back_link( '<i class="dt-icon-the7-misc-006-1" aria-hidden="true"></i>' ); | |
} | |
if ( $config->get( 'post.navigation.arrows.enabled' ) ) { | |
$next_text = '<i class="icomoon-the7-font-the7-arrow-29-2" aria-hidden="true"></i>' . | |
'<span class="meta-nav" aria-hidden="true">' . __( 'Next', 'the7mk2' ) . '</span>' . | |
'<span class="screen-reader-text">' . esc_html( $args['next_src_text'] ) . '</span>' . | |
'<span class="post-title h4-size">%title</span>'; | |
// We use opposite order. | |
$next_link = get_previous_post_link( | |
'%link', | |
$next_text, | |
$args['in_same_term'], | |
$args['excluded_terms'], | |
$args['taxonomy'] | |
); | |
$next_link = str_replace( '<a', '<a class="nav-next"', $next_link ); | |
if ( ! $next_link ) { | |
$next_link = '<span class="nav-next disabled"></span>'; | |
} | |
$output .= $next_link; | |
} | |
if ( $output ) { | |
$output = '<nav class="navigation post-navigation" role="navigation"><h2 class="screen-reader-text">' . esc_html( $args['screen_reader_text'] ) . '</h2><div class="nav-links">' . $output . '</div></nav>'; | |
} | |
return $output; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Please try this code in your child theme functions.php