jQuery(document).ready(function($){ if(typeof acf == 'undefined') return; // ACF Flexible Content: Directly add layout if there's only one layout var flexible_content_open = acf.fields.flexible_content._open; acf.fields.flexible_content._open = function(e){ var $popup = $(this.$el.children('.tmpl-popup').html()); // Count layouts if($popup.find('a').length == 1){ acf.fields.flexible_content.add($popup.find('a').attr('data-layout')); return false; } // More than one layout? Continue the JS execution return flexible_content_open.apply(this, arguments); } });