I created a plugin and tried to use its shortcode in a Custom HTML Widget, but for some reason it's outputting [my_shortcode_name] instead of executing the shortcode.

The shortcode works fine if I place it on the page or in a Text Widget.

How can I make it work in a Custom HTML Widget?

1 Answer 1


I was able to make it work by adding these two lines to my theme's functions.php file:

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

The Custom HTML Widget now correctly executes the shortcode function and outputs the result.

  • Mark your own answer as Accepted Answer to help other people searching solution for same issue. Apr 28, 2019 at 9:40
  • 1
    @QaisarFeroz - You have to wait two days before accepting your own answer. It's a global Stack Exchange restriction. meta.stackexchange.com/q/6044/258412 Apr 28, 2019 at 9:55
  • OK, Stay blessed. Apr 28, 2019 at 9:57
  • Thanks, for me it worked only with the last filter: add_filter( 'widget_text', 'do_shortcode'); Sep 4, 2023 at 9:11

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.