By default, WordPress does not execute shortcodes in text widgets or excerpts. If you need to insert a shortcode into a text widget and/or excerpt, you must first insert the following code into your functions.php:
//Enable Shortcodes in WordPress Excerpts and Text Widgets. Add to functions.php add_filter('the_excerpt', 'do_shortcode'); add_filter('widget_text', 'do_shortcode');
Make sure the code goes within the php tags “<?php ?>” of your themes functions file (I recommend placing all additional snippets just inside the opening php tag for easy maintenance). This example changes the number of related products shown on each product page to 6. Therefore, if you don’t want 6 related products on each page, change the 6 in ‘posts_per_page’. Save and enjoy!
Note: You will need to add this code snippet again if you update/change your theme.