Support

Account

Home Forums Backend Issues (wp-admin) Theme-specific location rules

Solved

Theme-specific location rules

    • dbrabyn

    • April 16, 2019 at 2:33 am

    Some of my field groups are only relevant to a specific theme, others are used by the 3 themes I have installed.

    I’d like to have as single overall ACF setup to manage. I want to be able to switch themes without having to modify the ACF setup. And my client can only see field groups that make sense to his.her theme.

    How would you go about putting this together? Custom location rule? PHP registering? JSON? Something else?

    Thanks.

  • I would not have enough information yet to decide.

    Are these all self-standing themes? or are they child themes all based on a single parent theme? Some combination of this?

    How are these field groups currently registered for each theme?

    • dbrabyn

    • April 16, 2019 at 7:04 am

    Hi John,

    They are self-standing themes (however if a client need some customization I would implement that via a child theme).

    My aim is to have a core ACF setup that I can tweak if a theme requires it. Right now I have used the admin UI to register the field groups. Ideally ACF would have a native “If current theme is xxxxxxx” location rule.

    Eventually the fields will be deployed on the sub-sites of a multisite network which I hope will not add too many constraints (had to start this project somewhere and it wasn’t there).

  • If I was going to do something like this, starting at the beginning and knowing that I would be moving to a multisite setup……..

    I would start by setting up multisite and I would create a “master theme” where I would create all of the field groups. This master theme would have an acf-json folder so that when I made changes to a field group the changes would be saved in the json folder. Without doing this you would need to import the field groups to each them anyway, so you would not have a master location for maintaining all the field groups.

    I might actually create the acf-json folder in the root of /themes/ rather than in the theme and then use the custom save and load points in ACF to https://www.advancedcustomfields.com/resources/local-json/

    
    $path = dirname(get_stylesheet_directory()).'/acf-json';
    

    In each of the other themes I built I would create my own function to load the field groups that are needed for each theme from this master theme json folder using a variation of this https://github.com/Hube2/acf-filters-and-functions/blob/master/acf-load-parent-theme-field-groups.php… this was something that I created either before acf allowed multiple load points or before I realized they existed. I keep it around because it’s a good reference. I would only load the groups I needed, filtering by the group key.

    My goal would be to limit the number of places that these field groups existed and this would limit it to 1 locations and one place where they could be edited.

    • dbrabyn

    • April 17, 2019 at 1:10 am

    That’s brilliant. I hadn’t thought of a shared core json folder. Thanks a lot.

    • dbrabyn

    • April 17, 2019 at 1:12 am

    Arrgh! Wrong button. Doesn’t look like I can edit the “This solved my question” label. Sorry.

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

You must be logged in to reply to this topic.

We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.