I would like to load shortcode stylesheet only when it will be put in text widget. Please help somebody.

  • 1
    Your question is not clear and seems to have several parts but I think part of the answer is here: wordpress.stackexchange.com/a/101515/21376
    – s_ha_dum
    Commented May 9, 2014 at 14:28
  • In standard WordPress a shortcode in a text widget doesn't do anything, it just prints out the shortcode, it's not processed
    – Tom J Nowell
    Commented May 9, 2014 at 14:39
  • @ s_ha_dum and Tom thanks for your response. I have found the solution :)
    – Babu
    Commented May 9, 2014 at 15:12
  • Then please add it as answer.
    – kaiser
    Commented May 9, 2014 at 15:44

1 Answer 1


I think you should be able to register your stylesheet with wp_register_style(), then load the stylesheet via wp_enqueue_style() from within the shortcode's function, so it only loads when the shortcode is executed.

For a rundown on how this will work here's a good article. It refers to scripts, but I believe the same is true for styles: http://mikejolley.com/2013/12/sensible-script-enqueuing-shortcodes/

(Also, if you need shortcodes to run in text widgets be sure to add this to your plugin or functions.php file: add_filter('widget_text', 'do_shortcode');)

  • 1
    Thanks a lot Michelle! I put wp_enqueue_style() within shortcode's function and now the stylesheet loads only when shortcode is excuted. I'm very grateful to you :)
    – Babu
    Commented May 9, 2014 at 15:09

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