You can’t predict if something will include your box further down the line, so to do it “the right way”, you’ll need to add your CSS/JS early.
The not-so-right way could be to add output buffering and analyze the output to see if your box got included somewhere, and then add your HTML to the head of the document. It’s not clean, and I’d make it optional (and disabled in the default mode so the user has to activate it) and add some explanation as it can get confusing when you wonder why something does/does not work on different pages, and it’s often a pain to debug these things if you’re not aware of them.
Related Posts:
- Use wp_enqueue_scripts, not wp_print_styles?
- How to combine multiple CSS files and concatenate JavaScripts if WordPress recommends enqueuing them?
- Relative path instead of absolute for wp_enqueue_script
- Custom Admin CSS styles to style media uploader?
- How to insert html/css/javascript code to wordpress plugin
- Child theme stylesheet not always overriding “index”
- How can I force Dynamic CSS via ACF values to update on page load?
- functions.php – inject inline css from file
- enqueing Javascript and CSS
- Load custom CSS before admin CSS
- Dequeue styles with query doesn’t work
- Bootstrap Integtration
- Bootstrap 4 Optimization
- plugin not loading my css and js
- Could the WP script/style loader be used to concatenate and gzip scripts and styles in the front-end?
- How can I get a list of all enqueued scripts and styles?
- Remove Open Sans from Twenty Twelve theme
- How to load scripts/styles specific for a page
- Enqueue Google Web Fonts Without Messing Up Symbols In URL
- Inbuilt style for jquery-ui-datepicker
- Why is style.css not being enqueued?
- How to conditionally enqueue a stylesheet only for a certain page(s)?
- How to enqueue style before style.css
- How to add stylesheets only to pages with specific shortcode?
- wp_enqueue_scripts, wp_register_scripts, wp_print_scripts: i’m confused
- What is the correct way to enqueue multiple CSS files?
- Remove wp_add_inline_style
- Is it possible to enqueue a raw CSS string directly from within a template file?
- Why I can’t add a CSS style in this WordPress theme?
- How can I dequeue a Plugin Stylesheet?
- Why isn’t my theme processing SASS?
- Adding style sheet to specific page
- How do I load custom scripts and styles for a page?
- How Can I Use A Child Theme Effectively When Parent’s CSS Is Located in a ‘CSS folder’?
- Disable child theme css on certain pages
- When enqueing a stylesheet, is it possible to remove the type attribute? [duplicate]
- Enqueued Stylesheets Effecting Admin Styles
- wp_enqueue_script + how to load JS or CSS in one URL merge call?
- Load custom css after bootstrap
- Enqueue style for Password Reset page
- The correct way to include JavaScript and CSS in my WordPress Themes
- Is it possible to change the path of a css file that is registered through wp_enqueue_style()?
- get_stylesheet_uri returns wrong path
- Override load-styles.php with admin screen css
- CSS file not registering through add_action
- Relative path in wp_register_style not working
- getting url in wp_enqueue_style
- How the Css File is Linked without calling it in header.php?
- Loading different stylesheet on WordPress pages?
- Use wp_add_inline_style to add code to before wp_head?
- why enqueued styles in header.php shows in footer?
- Adding external stylesheet after ALL other styles
- Different ways to load child theme css
- How to enqueue a random css style?
- How to override Bootstrap css with my child theme css in wordpress?
- Enqueue styles in new site editor in WordPress 5.9
- How to integrate my HTML and javascript into my child theme
- How to organize priority of plugins CSS files?
- why this media query is not working / not loading when I put it in child theme?
- How do I make header.php use different css for different pages?
- Load CSS in footer, like your can with JS?
- Enqueuing a script before anything else
- Child Theme CSS not showing at all
- Faster fonts on mobile
- wp_enqueue_scripts and CSS
- Custom Plugin – CSS works, JS doesn’t
- Ordering stylesheet above using functions.php
- Display Something in the Header After All Styles are Loaded
- My CSS suddenly doesn’t load anymore [closed]
- Append style tag in head while shortcode runs
- How can I move my custom css to the very bottom of the head section?
- CSS getting injected into index from somewhere after theme/custom CSS is loaded, overriding all of my CSS [closed]
- Theme JS is available but theme CSS isn’t
- How would one set or override a Fallback font for characters in second language?
- First element/selector of enqueued CSS file breaks
- I want to set global directory locations for my CSS and JS locations. How?
- is there a way to get all queued scripts/styles into a template without `get_header()`?
- Advanced method to control cache of enqueued style/script
- Save custom option in CSS file
- How to enqueue stylesheets in child-theme functions.php?
- Dequeing Parent Fontawesome Deques Parent Styles
- Add inline CSS to login page with wp_add_inline_style
- Set different css stylesheet for specific pages [duplicate]
- My Child Theme CSS Isn’t Working
- Font size decreases when child theme is created from parent theme?
- Enqueue CSS and Script only if needeed
- How do I dequeue a Stylesheet, stored in an ‘Assets’ folder?
- Controling css order
- Why are my parent styles loading after my child styles?
- How to make CSS load live based on options clicked in the theme customizer?
- Replacing parent theme’s IE-specific CSS
- Change Login CSS – Include instead of echo
- Browser stacks different versions of style.css
- Enqueue MCE Editor CSS in admin page
- Custom theme – Bootstrap CSS not loading via wp_enqueue_style or otherwise
- How enqueue CSS out of theme folder?
- How can I make the wordpress editor apply the selected template?
- All of my Scripts and Enques are getting file not found
- wordpress – site not update after update style.css
- adding a favicon to site2 – site1/site2/favicon.ico