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');
)
Related Posts:
- How to add stylesheets only to pages with specific shortcode?
- Hide/show content starting in the middle of a paragraph
- How to add ‘class’ attribute into shortcode [audio]?
- How to link to a alternative page in CSS
- How to use shortcodes on a widget sidebar when doing an ajax call?
- Video size and border radius using a shortcode
- Is it possible to ignore the first Line Break in a preformatted Div from a shortcode?
- How can I included CSS to a page or a shortcode? [closed]
- Two different inner shortcode under shortcodes or multiple nesting of inner shortcodes
- Make shortcode’s Bootstrap CSS override the theme’s CSS, how?
- Shortcode inside text widget do not call enqueue style
- How to display html element and php string in the same line?
- the_excerpt displaying code inside style tag
- How to fix transparency in product sliders / featured products on home page?
- How to Convert Shortcode into a link?
- How to create a shortcode with 1 parameter (atts)
- shortcodes output before content [duplicate]
- WordPress adds br in between my shortcode
- Shortcodes, HTML tables, and multiple rows
- WP_enqueue_script inside shortcode?
- Shortcode to Gutenberg-block: additional text on front-end and conditional display
- How navigation works in custom loop within shortcode?
- Use [shortcode=”value”] instead of [shortcode att=”value”]?
- I dont want to show shortcode in tag
- WordPress shortcode doesn’t working on HomePage
- Can’t understand $atts in functions?
- Add attribute to shortcode dynamically
- Execute shortcode twice in the same page
- How to parse this shortcode?
- Shortcode with hyphen doesn’t work
- Shortcode parsed incorrectly because of heredoc
- Shortcode “post_per_page” not working
- Shortcode is running in page editor
- Creating shortcode with parameter
- Video Shortcodes not working in WordPress
- Create shortcode in Child Theme?
- Get post object in shortcode function
- How to insert image and text from admin panel throughout my theme
- Create a short code to display a specific loop
- How to add shortcode to HTML file (not showing on website)
- Custom Shortcode: define cursor position/insertion point?
- Buddypress shortcode for tabs [closed]
- show shortcodes in editor
- Image Shortcode from ACF ID
- Page code showing in WP Dashboard
- echo do_shortcode just prints the shortcode name and not its content
- How to create a shortcode with html and php code
- PHP Running On CMS Side of WordPress
- Insert shortcode between ”
- Create a shortcode to use in visual editor
- do_shortcode doesn’t work on some pages
- Custom youtube shortcode that uses $content
- How to build dynamic pages?
- How to reload the shortcode content when the database is changing
- Best way to include reusable sections in page content
- Regenerating WordPress shortcodes based on value with AJAX
- Custom shortcode to display posts, first post is full
- Form shortcode with multiple options as attributes
- How to add data attributes to the wordpress audio shortcode
- Beginner’s question about shortcodes
- How to create a dropdown of shortcodes in edit mode for posts
- Multiple instances of the shortcode on the same page
- Shortcode from admin textarea to page
- get data with shortcode
- Replace shortcode with output in database?
- Wrap php in shortcode
- Adding my own custom woocommerce shortcode to child theme, how?
- contact form 7 :create shortcode usable in email message [closed]
- Excerpt Length & List Category Posts Plugin
- Iteratively add sub shortcodes to php array
- How to execute a shortcode?
- Shortcode, Concatenating & Parse error: syntax error, unexpected T_FOREACH
- Getting Shortcode Attributes befor content is displayed by the template
- How to remove double quotes in a shortcode?
- Shortcode to appear and show the date not code in Title and description of my website
- Colon is Missing In My Website Url in WordPress Shortcode
- Shortcode not working inside div html
- Multiple shortcodes with embedded JavaScript code in same page, how?
- Contact Form 7 shortcode is commented out, but I receive spam emails from it
- How can I disable(remove) wpautop (wptexturize, convert_chars) for specific shortcodes only?
- How to load specific template page in a custom shortcode
- WordPress keeps automatically inserts
- shortcode is not rendered
- nested shortcodes from different plugins. too complex? [duplicate]
- Contact form code not working. Need help!
- How to make shortcode enabled in JSON Feeds?
- How to add a shortcode to an HTML image tag
- Automatically add class-attribute to gallery?
- Shortcode works from functions.php but not from included file
- Why can’t I type [ ] opening and closing brackets on the Visual tab?
- Video shortcode inside tabs shorcode NOT working
- How to add meta slider lite or other slider to main page header in pinboard theme
- Str_replace using shortcode with multiple changes
- div having different appearances in different themes
- Escaping a shortcode so it displays as-is [duplicate]
- WordPress do_shortcode first iteration
- Add a short code to a plugin
- Add widget/shortcode to sidebar OUTSIDE of the theme
- How to remove https:// from shortcode generated url
- How to enable on custom shortcodes