Home Forums General Issues using ACFPro to load custom CSS for a page or post


using ACFPro to load custom CSS for a page or post

  • I want to sometimes have some custom CSS applied to only a particular page or post. I’m relatively new to ACF and not too sure how to implement this. I read another post about CSS in the admin end, but I’m after something for a one off page or post as required.

    I don’t think there’s any magic way to do this using the built-in tools or functions (I could be wrong), but this is what I’ve been thinking:

    • have an ACF for CSS data
    • have an ACF checkbox to determine if the CSS should be applied or not
    • in the page template check for both and if they exist and the cb is active, apply said CSS

    But I’m not exactly sure how to do it. So first off, is what I want to do above the right way to go about it?

    I COULD just load something like the CSS Plus plugin, but my idea is to get away from forever installing new plugins. Would I be better off just using the plugin? It does format nicely within the post admin area (although I’ve just realised it doesn’t appear on custom post types, so ACF may be the only way to go).

    The theme will be my own, ie it’s a work in progress (based on _s).

    Custom CSS for one page (using the above method) feels like it’s doable, but what about having CSS for a set of posts? The CSS can be lengthy, and generally I wouldn’t want it loaded for all pages/posts, how could I have it apply to a set of posts/pages/custom types without overloading the database—by that I mean to not repeat the same CSS throughout the database).

    ie Could I somehow attach the CSS to a taxonomy? Probably a tag more-so than a category, but either.

    Any thoughts would be appreciated.

  • Hi @madivad,

    I must say your implementation is quite complex but if you are not willing to use a plugin to simplify things, another option would be to use the acf/input/admin_enqueue_scripts action to register the custom styles.

    This action is limited to pages where field inputs are generated.

    You can have a look through the following link:

Viewing 2 posts - 1 through 2 (of 2 total)

The topic ‘using ACFPro to load custom CSS for a page or post’ is closed to new replies.