[resolved] Problem with 'read more' link with automatic and manual excerpts (3 posts)

  1. Alkorr
    Posted 2 years ago #

    Hi. My posts sometimes have manual excerpt, some others don't.

    On my homepage, <?php the_excerpt(); ?> either shows the manual excerpt or the automatic excerpt (which refers to the first 55 words of the post’s content) if there is none.

    When there is a manual excerpt, I use this function to add a 'read more' link to full post:

    function excerpt_read_more_link($output) {
     global $post;
     return $output . '...<a href="'. get_permalink($post->ID) . '">' . 'Read more' . '</a>';
    add_filter('the_excerpt', 'excerpt_read_more_link');

    When there is an automatic excerpt, I use this other function to show the 'read more' link to full post:

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

    The problem is on my homepage, I use <?php the_excerpt(); ?> but when there is no manual excerpt, the 'read more' link is showing although it shouldn't. Therefore there are 2 'read more' links under automatic excerpts (one for the empty manual excerpt, and the one for the automatic excerpt).

    What can I do so the 'read more' link for manual excerpts only shows when there actually is a manual excerpt?

    Thanks for your help!

  2. paulwpxp
    Font hero
    Posted 2 years ago #

    In your 2nd function posted above, add the check if ( has_excerpt()).

    Actually you can go see the real working example in 2011's functions.php.

  3. Alkorr
    Posted 2 years ago #

    Hi paulwpxp, thanks a lot! :)

Topic Closed

This topic has been closed to new replies.

About this Topic