Gutenberg or not to Gutenberg with ACF

The Gutenberg editor is pretty fantastic, and you can do all sorts of things. I personally love it.

However, if you want to use ACF to manage the content on a particular page template, you can’t really rely on ACF’s ‘Hide on Screen’ functionality in the field group editor.

Here’s a simple function you can use to turn off the Gutenberg editor on pages with those specific templates.

add_action('init', 'my_disable_editor');
function my_disable_editor() {

	// get the current post ID
	$post_id = $_GET['post'] ? $_GET['post'] : $_POST['post_ID'] ;

	// if it's not set, ignore the function
	if( !isset( $post_id ) ) return;

	// find the page template of the current post
	$template_file = get_post_meta($post_id, '_wp_page_template', true);

	// hide the gutenberg editor if one of these page types
	// edit the following to suite your page templates
	if(
	    $template_file == 'page-templates/page-this.php' ||
	    $template_file == 'page-templates/page-that.php' ||
            $template_file == 'page-templates/page-other.php' 
	) {
	    remove_post_type_support('page', 'editor');
	}
}

Leave a Reply

Your email address will not be published.