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:
- 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.
- Improved Engagement: Showing post titles encourages users to click and explore additional content, increasing engagement on your website.
- Enhanced User Experience: Meaningful post titles eliminate ambiguity and confusion, improving the overall user experience.
- Better Content Discovery: Post titles on navigation buttons pique curiosity, leading to the discovery of relevant content.
- SEO Benefits: Including post titles helps search engines understand the content hierarchy and potentially improve indexing and ranking.
- 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;
}
Was this helpful?
YesNo