2

I am using this code in functions.php to append a button for link to a post.

function new_excerpt_more($more) {
 global $post;
 return '<a class="excerpt-readmore" href="'. get_permalink($post->ID) . '">Read more</a>';
}
add_filter('excerpt_more', 'new_excerpt_more');

In front-page.php I have get_template_part('content-ctp'); and in that file I have

$args = array(
    'post_type' => 'radovi'
    );
$ctp = new WP_Query($args);
...
the_excerpt();

Is there a way to not have the read-more button only for this specific loop? I don't think I can check with if(!is_front_page()) on filter since I also have 2 more loops on front page where I need that button. Any suggestions on how to do it properly the Wordpress way?

1 Answer 1

5

You can just remove the filter before calling the_excerpt and then add it back afterwards...

remove_filter('excerpt_more','new_excerpt_more');
the_excerpt();
add_filter('excerpt_more', 'new_excerpt_more');
1
  • LOL nice trick, ty :) Commented Jul 6, 2016 at 10:19

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.