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();
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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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