Astra

Include the “Post Title” in the Next-Previous post buttons in wordpress-Astra theme

If you notice, i have changed the class of the arrows icons, so they dont hide in mobile screen “ast-left-arro” & “ast-right-arro”

Here are the advantages of changing the Next-Previous post buttons to show the post title in WordPress:

  1. Clear Navigation: Displaying post titles provides clear navigation cues, improving user experience and helping readers understand the context of the posts they’re navigating to.
  2. Improved Engagement: Showing post titles encourages users to click and explore additional content, increasing engagement on your website.
  3. Enhanced User Experience: Meaningful post titles eliminate ambiguity and confusion, improving the overall user experience.
  4. Better Content Discovery: Post titles on navigation buttons pique curiosity, leading to the discovery of relevant content.
  5. SEO Benefits: Including post titles helps search engines understand the content hierarchy and potentially improve indexing and ranking.
  6. Increased Accessibility: Displaying post titles assists users relying on screen readers or assistive technologies.
    
add_filter( 'astra_single_post_navigation', 'astra_change_next_prev_text' ); /** * Function to change the Next Post/ Previous post text. * * @param array $args Arguments for next post / previous post links. * @return array */ function astra_change_next_prev_text( $args ) { $next_post = get_next_post(); $prev_post = get_previous_post(); $next_text = false; if ( $next_post ) { $next_title = substr( $next_post->post_title, 0, 35 ); if ( strlen( $next_title ) === 35 ) { $next_title = rtrim( $next_title, "!,.-" ) . '...'; } $next_text = sprintf( '%s <span class="ast-right-arro">→</span>', $next_title ); } $prev_text = false; if ( $prev_post ) { $prev_title = substr( $prev_post->post_title, 0, 35 ); if ( strlen( $prev_title ) === 35 ) { $prev_title = rtrim( $prev_title, "!,.-" ) . '...'; } $prev_text = sprintf( '<span class="ast-left-arro">←</span> %s', $prev_title ); } $args['next_text'] = $next_text; $args['prev_text'] = $prev_text; return $args; }

Leave a Reply

Your email address will not be published. Required fields are marked *