0

I am confused about the behaviour of the_excerpt() and get_the_excerpt().

My objective is to have a manual excerpt and display a continue reading.

I went through this article, and apparently the_excerpt() is not meant for that.

So I'm trying get_the_excerpt() instead, and I still don't get the continue reading for some reason.

Again, the idea would be to display a manual excerpt and a continue reading link.

EDIT (forgot to add): In my functions.php I have:

function custom_excerpt_length( $length ) {
    return 1;
}
add_filter( 'excerpt_length', 'custom_excerpt_length', 999 );


// Add more-link text to excerpt
function new_excerpt_more( $more ) {
    return '... <a class="more-link" href="'. get_permalink( get_the_ID() ) . '">' . __('Continue Reading', 'baskerville') . ' &rarr;</a>';
}
add_filter( 'excerpt_more', 'new_excerpt_more' );

I have tried in my content.php:

the_excerpt();

and

get_the_excerpt();
1

1 Answer 1

3

The problem is the difference between the teaser and excerpt which is mistaken one for another in many case.

The excerpt_more filter that you are using will change the teaser more text, not the excerpt. The right filter for this is the get_the_excerpt. But it doesn't change the [...] of the excerpt, it gives you the ability to change the excerpt itself. So in this case you have to add the Read more to the excerpt and return that.

Here's the code -

// Add more-link text to excerpt 
function new_excerpt_more( $excerpt ) { 
    return $excerpt. '... <a class="more-link" href="'. get_permalink( get_the_ID() ) . '">' . __('Continue Reading', 'baskerville') . ' &rarr;</a>'; 
} 
add_filter( 'get_the_excerpt', 'new_excerpt_more' );

I will suggest you to read the article that you linked to your post again now. This will give you a better understanding of the difference now.

1
  • 1
    Thanks for sharing your answer, helped me a lot! Also, I had to implement the the_excerpt filter to return nothing to hide [...] for automatic excerpts: add_filter('excerpt_more', '__return_false');. Because my website has both; Manual and Automatic excerpts. Aug 10, 2022 at 18:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.