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.

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 ☕️.

Thank you for your feedback and support!

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 *

This site uses Akismet to reduce spam. Learn how your comment data is processed.