• Resolved Ashley Michèlle

    (@ashleymichelle)


    I’m trying to use this…

    <div class="readmore"><a class="readmore" href="'. get_permalink( get_the_ID() ) . '"><small> CONTINUE READING</small></a></div>

    …to show below the excerpt on all of my posts. You can see what’s going on HERE.

    My functions.php:

    // Replaces the excerpt "more" text by a link
    function new_excerpt_more($more) {
           global $post;
    	return '<div class="readmore"><a class="readmore" href="'. get_permalink( get_the_ID() ) . '"><small> CONTINUE READING</small></a></div>';
    }
    add_filter('excerpt_more', 'new_excerpt_more');

    I get the ‘read more/continue reading’ button, but only when the post doesn’t have a manual excerpt. I want ‘continue reading’ to display beneath all of the posts, with my formatting.

    Help is greatly appreciated! I am over my head on this one…
    Thanks so much!

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter Ashley Michèlle

    (@ashleymichelle)

    So, I’m currently using the below code to execute the above:

    function custom_excerpt($text) {  // custom 'read more' link
       if (strpos($text, '[...]')) {
          $excerpt = strip_tags(str_replace('[...]', '<div class="readmore"><a class="readmore" href="'. get_permalink( get_the_ID() ) . '"><small>CONTINUE READING</small></a></div>', $text), "<a>");
       } else {
          $excerpt = '' . strip_tags($text) . '<div class="readmore"><a class="readmore" href="'. get_permalink( get_the_ID() ) . '"><small>CONTINUE READING</small></a></div>';
       }
       return $excerpt;
    }
    add_filter('the_excerpt', 'custom_excerpt');

    But, I’ve encountered one problem – I am now getting the […] after all of the auto excerpts. How do I manage to remove this?

    Thanks!

    Thread Starter Ashley Michèlle

    (@ashleymichelle)

    Figured it out! Was just a matter of adding one more bit of code.

    For anyone who is curious:

    function new_excerpt_more($more) {
    	return '';
    }
    add_filter('excerpt_more', 'new_excerpt_more');
    
    function custom_excerpt($text) {  // custom 'read more' link
       if (strpos($text, '[...]')) {
          $excerpt = strip_tags(str_replace('[...]', '<div class="readmore"><a class="readmore" href="'. get_permalink( get_the_ID() ) . '"><small>CONTINUE READING</small></a></div>', $text), "<a>");
       } else {
          $excerpt = '' . strip_tags($text) . '<div class="readmore"><a class="readmore" href="'. get_permalink( get_the_ID() ) . '"><small>CONTINUE READING</small></a></div>';
       }
       return $excerpt;
    }
    add_filter('the_excerpt', 'custom_excerpt');

    Works like a charm!

    Thanks for posting this, I was having the same problem and this solved it!

    One other question (I’m new to this type of coding)–how would I make the readmore link appear inline with the excerpt instead of on a new line?

    Specifically, I’m trying to get <excerpt>… read more. (I’d still like the ellipsis but adding the link.)

    Thanks in advance!

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘'Read More' not displaying after manual excerpt’ is closed to new replies.