Skip to content

Instantly share code, notes, and snippets.

@darylldoyle
Last active November 7, 2022 01:47
Show Gist options
  • Select an option

  • Save darylldoyle/7bf29e7bed938b39292495fe8b1f76bb to your computer and use it in GitHub Desktop.

Select an option

Save darylldoyle/7bf29e7bed938b39292495fe8b1f76bb 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 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' );
@darylldoyle

Copy link
Copy Markdown
Author

Updated jQuery selectors to not select sub-tabs as this breaks them. Only get first level tabs!

@jbjanot

jbjanot commented Dec 9, 2020 •

Copy link
Copy Markdown

Hello @darylldoyle. I would love to use this in a website, but sadly it is not working anymore in the latest ACF versions.
Did you had the chance to make it work on the latest ACF?

Thank you very much for this plugin.
See you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment