0

I've added the following code to my functions.php:

function new_excerpt_more($more) {
    global $post;
    return '<strong><a class="moretag" href="'. get_permalink($post->ID) . '">... Read More</a></strong>';
}
add_filter('excerpt_more', 'new_excerpt_more');

This adds a read more link to excerpts that have been automatically generated, i.e. an author hasn't specified anything in the excerpt field when posting an article.

So far so good.

However I would also like this to appear when something has been specified in this box, currently it only displays in the first instance.

Thanks

1 Answer 1

1

To show your custom excerpt more text when a post has a manual excerpt, you can filter the excerpt using the get_the_excerpt filter, use has_excerpt() (http://codex.wordpress.org/Function_Reference/has_excerpt) to determine whether the post has a manual excerpt or not, and append the output of your already-existing custom excerpt more function to the excerpt if not. Here's some code that I tested with your custom excerpt more function above, which does the trick:

function excerpt_more_for_manual_excerpts( $excerpt ) {
    global $post;

    if ( has_excerpt( $post->ID ) ) {
        $excerpt .= new_excerpt_more( '' );
    }

    return $excerpt;
}
add_filter( 'get_the_excerpt', 'excerpt_more_for_manual_excerpts' );
1
  • Still works in 2022! Just remember to implement the new_excerpt_more() or inline replace with whatever you need
    – Costa
    Feb 12 at 4:04

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.