How to remove “read more” link from custom post type excerpt

Is there a way I can add some kind of pre_get_posts() filter to strip out the “read more” link that appears at the end of the_excerpt() for only 1 certain custom post type that I specify?

If so, can someone please help me out with the code? I’ve been working at it for a while but haven’t gotten anywhere. Any help would be greatly appreciated. Thanks!

4 s
4

Put the following code in functions.php to show “read more” on all post types except custom_post_type.

function excerpt_read_more_link($output) {
  global $post;
  if ($post->post_type != 'custom_post_type')
  {
    $output .= '<p><a href="'. get_permalink($post->ID) . '">read more</a></p>';  
  }
  return $output;
}
add_filter('the_excerpt', 'excerpt_read_more_link');

Leave a Comment