Home Forums Add-ons Flexible Content Field Conditionally Load Flexible Content Layouts


Conditionally Load Flexible Content Layouts

  • I am working on a plugin that adds a flexible content field to all pages and that field has about 8 different layouts set up for it. What I would like to be able to do is conditionally load certain layouts depending on settings I have in my plugin. For example: If the my_plugin_setting_accordion is true, I want the accordion layout to appear as a layout option for the flexible content field.

    Does anyone have any experience trying this? If so, is there any documentation you can point me to for how to achieve this? I’ve tried googling solutions, but the only information (article) I found is 3 years old and feels a bit hacky. Also, the article I found posed one solution for themes, but I’m trying to achieve this within a plugin so that method wouldn’t work.

    I appreciate any help or direction I can get, thanks!

  • I covered a possible solution here

    It involves adding a load_field filter for the flex field, looping over the layouts and removing the ones you don’t want shown.

  • Thanks for the reply! However, the solution you linked to appears to be front-end focused. I’m looking for a way to conditionally remove it from the back-end when editing a page.

    The plugin I’m working on provides different types of content that can be added to a page. For example it has a basic content editor section, an accordion section, and a tabs section. These are all different layouts included in a flexible content section. But some of our clients may not need the tabs section. So rather than hacking the plugin for that particular site I’m trying to build a settings page where I could turn of the tabs section. So when the client goes to add content to a page, they don’t see the tabs layout as an option. Does that better explain what I’m trying to achieve? Please let me know if I can clarify anything or if I’ve misunderstood the post you linked to.


  • The comment I posted there is a method for showing or not showing the layout when editing. It will effect both the front end and the back end because the layouts removed will not exist in the flex field whenever they are removed.

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

The topic ‘Conditionally Load Flexible Content Layouts’ is closed to new replies.