How to use Woocommerce Shortcodes in your Widget in a ColourMag Theme

As the rather long winded title suggests, I was recently updating my Colormag theme (from Theme Grill) and after enabling the option to remove the front page and just use widgets, the woocommerce [recent_products] and [categories] shortcodes stopped working.

After digging around it was apparent that the woocommerce shortcodes (and indeed all others) simply don’t work in widgets!

It’s very useful for your colormag theme if using widgets on the front page. For example, on my Christmas Jumpers website, the front page looked like this (highlighted is the shortcode I wanted to use in the Top Section widget area).

Christmas Jumpers site showing shortcode in wordpress widget not working properly

How do I get wordpress shortcodes to work in my widget?

Luckily, it’s just one line of code to enable shortcodes in your widgets. You need to edit functions.php. If you’re not sure how to do this, check out a few guides on how to create a child theme. You don’t really want to be edited the main theme as future theme updates would wipe out your code.

Open functions.php in the wordpress admin (Appearance > Editor). At the bottom of the file (making sure it’s before the ?> tag if that exists).

add_filter('widget_text', 'do_shortcode');

Save the functions.php file. Now refresh your page and it should show the shortcode working (as seen below).

christmas jumpers website showing the woocommerce shortcode working in a widget

Leave a Reply

Be the First to Comment!

Notify of
avatar
wpDiscuz