Support » Themes and Templates » Problem with 'read more' link with automatic and manual excerpts

  • Resolved Alkorr

    (@alkorr)


    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!

Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Problem with 'read more' link with automatic and manual excerpts’ is closed to new replies.