0

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

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. – Qaisar Feroz Apr 28 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 – Pikamander2 Apr 28 at 9:55
  • OK, Stay blessed. – Qaisar Feroz Apr 28 at 9:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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