Saturday 23 September 2017

Shortcode is not working in Sidebar Widget: WordPress

If shortcode is not working in WordPress Text Widget in that case you need to use a Hook provide by WP to enable shortcode feature for sidebar widgets.

Also would like to add that by default shortcode do not work in the sidebar Widget, they only work in post, pages and custom post type; to make shortcode work in the sidebar widget you can follow the below steps:
1) Open your themes functions.php file and add below code.

add_filter( 'widget_text', 'shortcode_unautop' );
add_filter( 'widget_text', 'do_shortcode' );

These two line should be in the same order, the first line prevent shortcode line break to convert into paragraph and second line helps to expand the shortcode in sidebar widget.

2) Add a text widget and add shortcode into it and save the widget and you are done.

Version at the time of demonstration:
WordPress 4.8.2

Load disqus comments