How to remove products with specific tag from recent product shortcode in Woocommerce?

By default woocomemrce comes with a number of shortcodes which could enable us to achieve some of the functionalities without any coding.

One of those shortcodes is recent products shortcode. This shortcode when placed on a page or post will display recent products of the shop on that page.

In this tutorial we’ll learn how to remove products with specific tags from listing by this short code.

So first of all create a page or post and place the shortcode [recent_products] in that.


Now from front end go to the newly created page and you’ll see recent products listed there.


Now let’s say we want to remove the products with tag ‘xyz’ from this listing.

To do this add the following lines of code at the end of your theme’s functions.php file:

add_filter('woocommerce_shortcode_products_query', 'removeAudioTags');

   function removeAudioTags($args){

       $args['tax_query'] = array(array(

           'taxonomy' => 'product_tag',

           'field' => 'slug',

           'terms' => array('xyz'),

           'operator' => 'NOT IN'


   return $args;


You can access functions.php file here:


Save file after placing code.

Now go to a product and add a tag ‘xyz’ there.


Save the product after adding tag.

Now again go the page where shortcode has been placed from front end and you’ll see that specific product being removed from that listing page.


Editorial Staff

ThemeLocation Provides Wordpress & Woocommerce development & Customization services. Have a Project? Contact To discuss

Leave a Reply

Your email address will not be published. Required fields are marked *