Home › Forums › Feature Requests › Disable Layout from Showing in Template › Reply To: Disable Layout from Showing in Template
I think something changed in the code between 2017 when John’s solution was posted and now (ACF 5.8.5) – I had to edit the foreach loop to make this work without throwing an illegal offset error. Here’s my working code. It looks to see if someone is editing an ‘application’ custom post type – if they are not, it won’t show the ‘integration_logos’ layout.
add_filter('acf/load_field/key=field_5d9e369133b92', 'remove_layouts', 99);
function remove_layouts($field) {
if (!is_admin()) {
// not on front end
return $field;
}
// you need to check to see if it's where you want to remove the layout
$current_screen = get_current_screen();
if ('application' == $current_screen->post_type) {
return $field;
}
// move current layouts into a var
$layouts = $field['layouts'];
// clear layouts
$field['layouts'] = array();
// list of layouts you don't want to include
$remove = array('integration_logos');
foreach ($layouts as $k => $layout) {
$name = $layout['name'];
// check
if (!in_array($name, $remove)) {
$field['layouts'][ $layout['name'] ] = $layout;
}
} // end foreach
return $field;
} // end function
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.