The following code allows shortcode parsing for 'text' widget:

add_filter('widget_text', 'do_shortcode');

How to make a similar one for a custom widget?

I tried the following one but it didn't work:

add_filter('widget_CUSTOM_WIDGET_NAME', 'do_shortcode');

1 Answer 1


You can try the following:

 * Only allow shortcodes for a widget with a given title.
 * @see http://wordpress.stackexchange.com/a/160246/26350

function wpse_widget_shortcode( $text, $instance )
        // Only allow shortcodes for the widget with the following title:
        $title = 'Some Title'; 

        remove_filter( current_filter(), __FUNCTION__ );

        if( isset( $instance['title'] ) 
            && mb_strtolower( $title ) === $instance['title'] 
            $text = do_shortcode( $text );

        return $text;

add_filter( 'widget_text', 'wpse_widget_shortcode', 99, 2 );

where we target the given widget by it's title.

  • 1
    Thanks for the 'do_shortcode( $text );'! That was the key!
    – Ahmed Saad
    Commented Sep 5, 2014 at 4:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.