9

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!

3
  • If you wanted a quick and easy solution, you could always just display:none the read_more link on that specific CPT
    – Jonathan
    Commented Nov 11, 2013 at 22:04
  • Thanks, I thought about that. But I'd prefer to strip the link out completely if possible so that Google does not follow and cache these specific pages.
    – Evster
    Commented Nov 11, 2013 at 22:28
  • The answer to this question is theme specific and not specific to WordPress as different themes include different code for adding the read more link codex.wordpress.org/… Commented May 22, 2014 at 6:27

5 Answers 5

8

I fixed this by adding the below to functions.php

remove_filter('get_the_excerpt', 'wp_trim_excerpt');

Courtesy of Remove more or [...] text from short post

6

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');
1

An easy solution is to put following code inside style.css:

 a.read-more {
    display:none;
 }

This targets <a class="read-more">

1
  • Should be marked as the correct answer, because the method doesn't provide a parameter to override it.
    – sGambolati
    Commented Oct 25, 2018 at 20:59
0

What about this? Basically it's a way to customize the text by adding a callback function to the functions.php file. I'm thinking, however, if you just return a space instead, then it should override it and not display anything.

// Replaces the excerpt "more" text by a link
function new_excerpt_more($more) {
   global $post;
   return ' ';
}
add_filter('excerpt_more', 'new_excerpt_more');

I got this from The Wordpress codex

Edit:

This is untested, but what if you do this:

// Replaces the excerpt "more" text by a link
function new_excerpt_more($more) {
   global $post;
   if ($post->post_type == 'your-cpt')
   {
      return "&nbsp;";
   }
}
add_filter('excerpt_more', 'new_excerpt_more');

To reiterate, I haven't tested this, but may get you on the right track (i.e. var_dump($post) to see how you can bend it to your will from within the new_excerpt_more function.

3
  • I think you're on the right track, but pasting that exact code into my functions.php file actually breaks the entire site. Also, I'll need the function to grab only the posts from the 'staff-members' custom post type.
    – Evster
    Commented Nov 11, 2013 at 22:53
  • Thanks for the help! There's still some kind of error in the syntax there that takes down the whole site and loads a blank page. I will see if I can figure it out. Your logic on this seems sound.
    – Evster
    Commented Nov 11, 2013 at 23:41
  • You need to return $more end of the function otherwise all other post type will miss the more tag/text.
    – Sisir
    Commented May 22, 2014 at 4:40
-1
function custom_theme_developement_view_product_button(){
    global $product;
    $link = $product->get_permalink();
    echo '<a href="" class="added_to_cart wc-forward" title="View cart"></a>'; 
}
add_action( 'woocommerce_after_shop_loop_item', 'custom_theme_developement_view_product_button', 11 );

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.