WordPress: Shortcode in Text Widget
By default, WordPress doesn’t parse WordPress or other 3rd party shortcodes in text widgets. I often see people putting shortcodes into text widgets and wonder why nothing is displayed.
To parse and output shortcodes in text widgets, you need to modify your WordPress theme and put the following code into the “functions.php” file of the theme.
You’re simply hooking onto the widget_text filter hook of WordPress which passes and returns the content through the function you specify. In this case you’re sending the widget_text content to do_shortcode() which is a WordPress core function that parses shortcodes in a string/content.
And that’s it, you can now put shortcodes into WordPress text widgets.
Related
About Author
lost-in-code
I (Antonie Potgieter) am a software engineer/web developer located in South Africa. My full-time work is the management of Tribulant Software and the development of its software packages.
Comments