0

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 May 9 '14 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 May 9 '14 at 14:39
  • @ s_ha_dum and Tom thanks for your response. I have found the solution :) – Babu May 9 '14 at 15:12
  • Then please add it as answer. – kaiser May 9 '14 at 15:44
0

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');)

| improve this answer | |
  • 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 May 9 '14 at 15:09

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