0

I am using the_excerpt() to display an excerpt for a custom post.

I then use this code to change the default "Continued" link to "Read more" which is working fine:

function bm_excerpt_more_link( $excerpt ){
   $post = get_post();
   $excerpt .= '<a href="'. get_permalink($post->ID) . '">Read more</a>';
   return $excerpt;
}
add_filter( 'the_excerpt', 'bm_excerpt_more_link', 21 );

However the "Read more" link is shown on the next line, outside the excerpt's <p> tag.

E.g.

<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do 
eiusmod tempor incididunt ut labore et dolore magna aliqua.</p>
<a href="http://mytheme.dev/news-post-five/">Read more</a>

Is it possible to keep the "Read more" text on the same line as the excerpt, within the <p> tag of the excerpt, in the same way as the default "Continued" link?

E.g.

<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do 
eiusmod tempor incididunt ut labore et dolore magna aliqua … <a 
href="http://mytheme.dev/news-post-five/">Continued</a></p>

Thanks very much!

0

Simple function that changes the output of the “[…..]” text and replace with the permalink.

function bm_excerpt_more_link( $more ) {
 $post = get_post();
return '<a href="'.get_the_permalink($post->ID).'">Read More...</a>';
}
add_filter( 'excerpt_more', 'bm_excerpt_more_link', 21 );

Or you can remove "p" tag by adding this below line before your post loop.

  remove_filter('the_excerpt', 'wpautop');

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.