Use WordPress shortcodes in (sidebar) widgets

You’re probably here because you noticed that your shortcode isn’t working, instead it’s just showing as text.

No worries! This is by default. There is a quick fix for this. Imagine you want to show your related posts in the sidebar or social share icons in the navigation, or anything else that you created a shortcode for.

Before proceeding with any customizations in WordPress, it’s essential to set up a child theme. A child theme acts as a safe and efficient way to make modifications without affecting the parent theme. If you haven’t set up a child theme yet, follow this tutorial on How to Create a Child Theme for Customization. It will guide you through the process and ensure that your customizations remain intact even after theme updates.

I assume you already know how to edit your files. If not, I recommend you to always use the child theme so that you don’t overwrite any core files from your theme. After a theme update, the files will always get overwritten. A child theme doesn’t receive an update so it’s save to add new files/code.

You can also add it via Appearance > Theme editor > Your CHILD theme > functions.php

Add the following code to your functions.php

// Enable shortcodes in navigation and (sidebar) widgets.
add_filter( 'widget_text', 'do_shortcode' );
Code language: PHP (php)

That’s it! You can now use your shortcodes as a widget or navigation item.


Read updated post to add shortcodes to navigation menu too!

Leave your feedback and help us improve ๐Ÿถ

We hope you found this article helpful! If you have any questions, feedback, or spot any errors, please let us know in the comments. Your input is valuable and helps us improve. If you liked this article, please consider sharing it with others. And if you really enjoyed it, you can show your support by buying us a cup of coffee โ˜•๏ธ or donating via PayPal ๐Ÿ’ฐ.

More free knowledge, because why not?

One Comment

  • I’ve been surfing online greater than three hours today, yet I never found any attention-grabbing article like yours. It is pretty worth enough for me. In my opinion, if all webmasters and bloggers made excellent content as you probably did, the net can be a lot more useful than ever before.


Your thoughts matter, leave a reply ๐Ÿ’ฌ

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