Skip to content

Instantly share code, notes, and snippets.

@ControlledChaos
Forked from darylldoyle/acf-tab-merge.php
Last active August 23, 2023 10:20
Show Gist options
  • Save ControlledChaos/dcf17bfdcb59c30ebec318e53abfd98a to your computer and use it in GitHub Desktop.
Save ControlledChaos/dcf17bfdcb59c30ebec318e53abfd98a to your computer and use it in GitHub Desktop.
ACF Tab Merge
<?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 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("#acf_after_title-sortables .acf-postbox:not(.acf-hidden) > .acf-fields > .acf-tab-wrap > .acf-tab-group");
var tab_wraps = jQuery("#acf_after_title-sortables .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', 'merge_acf_tab_groups' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment