Home › Forums › Feature Requests › Disable Layout from Showing in Template › Reply To: Disable Layout from Showing in Template
I have done this for layouts based on a post type, not sure if this will help you at all, and you’d need to work out how to do it for a template
// the key is the field key for the flex field
// the priority is set exceedingly high to ensure it runs last
add_filter('acf/load_field/key=field_5808cd92035a5', 'remove_layouts', 99);
function remove_layouts($field) {
if (!is_admin()) {
// not on front end
return $field;
}
// this is the part I'm not too sure about
// you need to check to see if it's where you want to remove the layout
// then
if (!$condition) {
return $field;
}
// move current layouts into a var
$layouts = $field['layouts'];
// clear layouts
$field['lahyouts'] = array();
// list of layouts you don't want to include
$remove = array('layout_1', 'layout_2', 'etc...');
foreach ($layouts as $layout) {
// check
if (!in_array($layout['name'], $remove)) {
// keep this layout
$field['layouts'] = $layout;
}
} // end foreach
return $field;
} // end function
I don’t know if it’s possible, but it may be, to add a custom setting to for flex fields for active and then check all flex fields when loading https://www.advancedcustomfields.com/resources/adding-custom-settings-fields/
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
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 Privacy Policy. If you continue to use this site, you consent to our use of cookies.