Exclude filter on front page

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

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

Leave a Comment