Home › Forums › Feature Requests › Filter for flexible content layouts › Reply To: Filter for flexible content layouts
Thanks for all of the great direction guys! Wanted to add this here as well for anyone who wants to do this based on the page template. Still working on it, but this seems to be doing what we need for the moment:
add_filter('acf/prepare_field/name=YOUR_ACF_FIELD_NAME', function($field) {
global $post;
$template = get_page_template_slug( $post->ID );
$layouts = $field['layouts'];
$field['layouts'] = array();
if( $template == 'your-template-file.php' ) {
foreach ($layouts as $layout) {
if ($layout['name'] != 'specific_layout_1' && $layout['name'] != 'specific_layout_2') {
$field['layouts'][] = $layout;
}
}
return $field;
} else {
foreach ($layouts as $layout) {
$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.