2

On my blog on all my main loops I have it set to show the excerpt instead of the content

If I make a longer post and leave the excerpt text box empty, then wordpress will make it's own excerpt from my post and show the [...] or a custom link at the end. Thats great however if I DO enter my own excerpt into the excerpt textbox, it will show that text but it will not show the read more part added to it.

Does anyone know how I can make it always show a read more?

4

Perhaps a conditional statement like the following will work. The logic is: "If the post has an explicit excerpt, add a read more link. Otherwise, use default excerpt behavior."

if($post->post_excerpt) {
    the_excerpt();
    echo '<a href="'.get_permalink().'">Read More</a>';
} else {
    the_excerpt();
}

You can use this in combination with Gavin's suggestion to unify the appearance of the "Read More" link.

  • Hello, thanks that is pretty much what I was looking for (untested but looks good) thank you – JasonDavis Jan 5 '12 at 20:15
3

I know that question was more than 2 years ago but I think here's more correct answer.

function new_excerpt_more($more) {
    global $post;
    return $more . '<a href="'. get_permalink( $post->ID ). '" class="readmore">more &raquo;</a>';
}
add_filter('the_excerpt', 'new_excerpt_more');

Even if your excerpt is filled the "readmore" link will be print after the excerpt paragraph.

1

Add this in your theme's functions.php:

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

More info: Make the "read more" link to the post

Good luck!

1

I know it's three years late, but I found a better solution that it can even help me in the future:

First, clean the default excerpt more to remove the default ellipses [...]:

function clean_excerpt_more() {
    return '';
}

add_filter( 'excerpt_more', 'clean_excerpt_more' );

Then, we get the excerpt and add the link inline, into the same excerpt paragraph! (Most of the solutions above show the link out of the paragraph, in a new line).

function custom_the_excerpt( $excerpt ) {
    global $post;

    if( $post->post_excerpt ) {
        // If the post has manual excerpt,
        // it already has a point to end
        // the paragraph, so we don't want
        // the point + the ellipsis: ....
        // Clean it!
        $ellipsis = '';
    } else {
        $ellipsis = '...';
    }

    // Save the link in a variable
    $link = $ellipsis . ' <a class="moretag" href="' . get_permalink( get_the_ID() ) . '">' . __( 'Read more &raquo;', 'starion' ) . '</a>';

    // Concatenate the link to the excerpt
    return $excerpt . $link;

    }

add_filter( 'get_the_excerpt', 'custom_the_excerpt' );

Edit: A final note. You don't need to modify nothing else. Use the_excerpt(); normally to display the excerpt with the link.

Hope it helps to someone :)

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.