Advanced Custom Fields is great but sometimes, especially when re-using field groups across templates, the admin area can get a little overwhelming. Tabs help but not when you’re using multiple field groups. To get around this I used to use this plugin for merging ACF tabs. It worked very well but hasn’t been updated in around 2 years and therefore doesn’t work at all on the new versions of ACF.
I needed this functionality yesterday for a theme I was working on and so I decided to adapt the code to work with the new versions of ACF.
This has only been tested on ACF5 so may be a little off on the late 4.x versions.
<?php | |
/* | |
Plugin Name: ACF Tab Merge | |
Plugin URI: https://enshrined.co.uk/2017/06/14/merging-acf-field-group-tabs/ | |
Description: Merges tabs across field groups in ACF | |
Version: 1.0.0 | |
Author: enshrined | |
Author URI: https://enshrined.co.uk | |
*/ | |
/** | |
* Merge Advanced Custom Fields tab groups into a single group. | |
*/ | |
function enshrined_merge_acf_tab_groups() { | |
$screen = get_current_screen(); | |
if ( 'post' === $screen->base ) { | |
echo ' | |
<!-- ACF Merge Tabs --> | |
<script> | |
acf.add_action("ready", function( $el ){ | |
var tab_groups = jQuery("#postbox-container-2 .acf-postbox:not(.acf-hidden) > .acf-fields > .acf-tab-wrap > .acf-tab-group"); | |
var tab_wraps = jQuery("#postbox-container-2 .acf-postbox:not(.acf-hidden) > .acf-fields > .acf-tab-wrap").parent(".inside"); | |
// Merge the tabs | |
if ( tab_groups.length > 1 ) { | |
var firstBox = tab_groups.first(); | |
tab_groups.not(firstBox).each(function(){ | |
jQuery(this).find("li").appendTo(firstBox); | |
jQuery(this).parent(".acf-tab-wrap").remove(); | |
}); | |
} | |
// Merge the tab content | |
if ( tab_wraps.length > 1 ) { | |
var firstBox = tab_wraps.first(); | |
tab_wraps.not(firstBox).each(function(){ | |
jQuery(this).children().addClass("hidden-by-tab").appendTo(firstBox); | |
jQuery(this).parents(".acf-postbox").remove(); | |
}); | |
} | |
}); | |
</script>'; | |
} | |
} | |
add_action( 'admin_footer', 'enshrined_merge_acf_tab_groups' ); |
UPDATE: This is now available as a plugin on WordPress.org at https://wordpress.org/plugins/acf-tab-merge/