Home › Forums › Add-ons › Flexible Content Field › Deactivate/Disable a Layout › Reply To: Deactivate/Disable a Layout
there isn’t any real way to disable a layout, but I did do something recently that might help you. What I needed was to exclude specific layouts if the client was not editing a specific post type.
In a really simplified example this is what I did
add_filter('acf/load_field/key=field_5808cd92035a5', 'remove_layout', 99);
function remove_layout($field) {
global $post;
if (!is_admin() || !is_object($post) || (!isset($post->post_type) || !isset($post->ID))) {
return $field;
}
$post_type = $post->post_type;
if ($post_type == 'acf-field-group' || $post_type == 'acf-field') {
return $field;
}
$layouts = $field['layouts'];
$field['layouts'] = array();
foreach ($layouts as $layout) {
if ($layout['name'] != 'layout_name_to_remove') {
$field['layouts'][] = $layout;
}
}
return $field;
}
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.