Dynamically add stylesheets/js?

Is there a good way to dynamically enqueue css/javascript other than using a child theme?

For instance, I have custom gallery plugin for posts that uses its own CSS/js. I don’t want to add the CSS/js on every page load, but only on posts that actually have the Gallery.

Typically, I’d hook wp_enqueue_script() in functions.php.

What’s the best way to do this in Cwicly?

Hey @rmnnet.

You can add your code via Fragments and set a condition where to load.
Use Cwicly’s Code Block.

I’m not sure that will work…

I need to use PHP to check if the post has a Gallery (which is an ACF gallery), and so that has to happen early.

When does Cwicly call whatever would add the Code Block?

I guess you have full control about what’s happening, but can’t tell for sure.

I’ve used this method inside Code Blocks in Oxygen before. I’ll check tomorrow if I needed to do anything special, but I’d imagine it’d work with Cwicly as well.

EDIT: Here’s how it was done with Oxygen: Self-contained Re-usables in Oxygen

The same thing should work with any page builder that has a code block. You can also use a snippet manager instead of downloading the My Custom Functionality plugin.