+5 votes
in CMS Tips by (40.5k points)
The posts in the "Astra" theme of WordPress show "Previous post" and "Next post" instead of their titles in the navigation. How can I replace Previous/Next with titles of the previous and next posts?

1 Answer

+2 votes
by (353k points)
selected by
Best answer

You need to add a filter in the file "function.php".
From Dashboard -> Appearance -> Theme Editor, open the file "function.php" and add the following lines of the code at the bottom of it. This filter will fetch titles of the previous and next posts and display them in navigation in place of previous/next strings.

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_text = sprintf(
            '%s <span class="ast-right-arrow">→</span>',
    $prev_text = false;
    if ( $prev_post ) {
        $prev_text = sprintf(
            '<span class="ast-left-arrow">←</span> %s',
    $args['next_text'] = $next_text;
    $args['prev_text'] = $prev_text;
    return $args;


Related questions