For example:
- I have a plugin that adds a box to the page.
- Box requires CSS file and JS file.
- Box can be added via shortcode, or via PHP or via widget.
My question is - how to include CSS & JS files only to pages where this box is present?
For JS file it's simple, as it's added to the footer.
But CSS file must be added to the <head>
section.
I know that some solutions involve string-parsing post_content and looking for shortcode. But this doesn't help when box is added via Widget or PHP.
Any tips?
Thank you.