Change the "Read more" text into something else

Hello,

I’m trying to change the “read more” text underneath each excerpt of an article into something else. I tried doing it as described in this article:

I entered the exact same code in my child theme in the functions.php like this:

function x_child_theme_setup() {
	// override parent theme's 'more' text for excerpts
	remove_filter( 'excerpt_more', 'x_excerpt_string' );
	remove_filter( 'the_content_more_link', 'x_content_string' );
}

add_action( 'after_setup_theme', 'x_child_theme_setup' );

function x_child_excerpt_string( $more ) {
	$stack = x_get_stack();
	if ( $stack == 'integrity' ) {
		return '<div><a href="' . get_permalink() . '" class="x-btn">mehr...</a></div>';
	} else if ( $stack == 'renew' ) {
		return ' ... <a href="' . get_permalink() . '" class="x-btn">Read More</a>';
	} else if ( $stack == 'icon' ) {
		return ' ...';
	}

}

add_filter( 'the_content_more_link', 'x_child_excerpt_string' );

Now the “read more” text gets removed, but it’s not being replaced with the new text I specified. The “x_child_excerpt_string” doesn’t even seem to execute. When I place an echo or even an exit in it, nothing happens. What am I doing wrong?

Hi @Muller,

Thanks for reaching out.

It will not work, you have removed the filters and re-added it. Instead, just remove that code and add this code to your child theme’s functions.php with your preferred string.

  function x_excerpt_string( $more ) {

    $stack = x_get_stack();

    if ( $stack == 'integrity' ) {
      return ' ... <div><a href="' . get_permalink() . '" class="more-link">' . __( 'Read More', '__x__' ) . '</a></div>';
    } else if ( $stack == 'renew' ) {
      return ' ... <a href="' . get_permalink() . '" class="more-link">' . __( 'Read More', '__x__' ) . '</a>';
    } else if ( $stack == 'icon' ) {
      return ' ...';
    } else if ( $stack == 'ethos' ) {
      return ' ...';
    }

  }
  add_filter( 'excerpt_more', 'x_excerpt_string' );

// Content More String
// =============================================================================
  function x_content_string( $more ) {

    return '<a href="' . get_permalink() . '" class="more-link">' . __( 'Read More', '__x__' ) . '</a>';

  }
  add_filter( 'the_content_more_link', 'x_content_string' );

These are pluggable functions, you don’t need to remove any filter, just add it and it will override the same function in the theme core.

Cheers!

1 Like

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.