{"id":13355,"date":"2019-08-06T10:51:51","date_gmt":"2019-08-06T08:51:51","guid":{"rendered":"https:\/\/hesmid.nl\/test\/?p=13355"},"modified":"2019-08-07T12:00:56","modified_gmt":"2019-08-07T10:00:56","slug":"disabling-gutenberg-on-certain-templates","status":"publish","type":"post","link":"https:\/\/hesmid.nl\/test\/disabling-gutenberg-on-certain-templates\/","title":{"rendered":"Disabling Gutenberg on certain templates"},"content":{"rendered":"\n<figure class=\"wp-block-embed-wordpress wp-block-embed is-type-wp-embed is-provider-bill-erickson\"><div class=\"wp-block-embed__wrapper\">\n<blockquote class=\"wp-embedded-content\" data-secret=\"nAQTCEYlHi\"><a href=\"https:\/\/www.billerickson.net\/disabling-gutenberg-certain-templates\/\">Disabling Gutenberg on certain templates<\/a><\/blockquote><iframe class=\"wp-embedded-content\" sandbox=\"allow-scripts\" security=\"restricted\" style=\"position: absolute; clip: rect(1px, 1px, 1px, 1px);\" title=\"&#8220;Disabling Gutenberg on certain templates&#8221; &#8212; Bill Erickson\" src=\"https:\/\/www.billerickson.net\/disabling-gutenberg-certain-templates\/embed\/#?secret=tNW2CoCLAK#?secret=nAQTCEYlHi\" data-secret=\"nAQTCEYlHi\" width=\"600\" height=\"338\" frameborder=\"0\" marginwidth=\"0\" marginheight=\"0\" scrolling=\"no\"><\/iframe>\n<\/div><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Using a plugin<\/h2>\n\n\n\n<p>The <a href=\"https:\/\/wordpress.org\/plugins\/classic-editor\/\">Classic Editor<\/a> plugin is great for disabling Gutenberg site-wide, but is not a good choice for selectively using it on certain pages. <\/p>\n\n\n\n<p><a href=\"https:\/\/wordpress.org\/plugins\/gutenberg-ramp\/\">Gutenberg Ramp<\/a> lets you disable Gutenberg on a per-post-type basis. You could use Gutenberg for posts, but keep the classic editor for pages.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Using a filter<\/h2>\n\n\n\n<p>We can use the&nbsp;<code>use_block_editor_for_post_type<\/code> filter for more fine-grained control. It passes two parameters:<\/p>\n\n\n\n<ul><li><code>$can_edit<\/code>, boolean, whether Gutenberg should be used to edit<\/li><li><code>$post_type<\/code>, string<\/li><\/ul>\n\n\n\n<!--more-->\n\n\n\n<p>I use <code>$_GET['post']<\/code> to get \nthe current Page ID from the URL. If that page is using certain \ntemplates, I\u2019ll disable the Gutenberg editor. I also use a similar \nfunction to remove the classic editor for current WordPress installs.<\/p>\n\n\n\n<p>I create a <code>disable-editor.php<\/code> file in my theme and update the <code>$excluded_templates<\/code> and <code>$excluded_ids<\/code> arrays specify where I want the editor turned off. <\/p>\n\n\n\n<p>This disables both the Gutenberg Block Editor and Classic Editor, \nallowing me to use a metabox for constructing the editing experience.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;?php\n\/**\n * Disable Editor\n *\n * @package      ClientName\n * @author       Bill Erickson\n * @since        1.0.0\n * @license      GPL-2.0+\n**\/\n\n\/**\n * Templates and Page IDs without editor\n *\n *\/\nfunction ea_disable_editor( $id = false ) {\n\n\t$excluded_templates = array(\n\t\t'templates\/modules.php',\n\t\t'templates\/contact.php'\n\t);\n\n\t$excluded_ids = array(\n\t\t\/\/ get_option( 'page_on_front' )\n\t);\n\n\tif( empty( $id ) )\n\t\treturn false;\n\n\t$id = intval( $id );\n\t$template = get_page_template_slug( $id );\n\n\treturn in_array( $id, $excluded_ids ) || in_array( $template, $excluded_templates );\n}\n\n\/**\n * Disable Gutenberg by template\n *\n *\/\nfunction ea_disable_gutenberg( $can_edit, $post_type ) {\n\n\tif( ! ( is_admin() &amp;&amp; !empty( $_GET['post'] ) ) )\n\t\treturn $can_edit;\n\n\tif( ea_disable_editor( $_GET['post'] ) )\n\t\t$can_edit = false;\n\n\treturn $can_edit;\n\n}\nadd_filter( 'gutenberg_can_edit_post_type', 'ea_disable_gutenberg', 10, 2 );\nadd_filter( 'use_block_editor_for_post_type', 'ea_disable_gutenberg', 10, 2 );\n\n\/**\n * Disable Classic Editor by template\n *\n *\/\nfunction ea_disable_classic_editor() {\n\n\t$screen = get_current_screen();\n\tif( 'page' !== $screen->id || ! isset( $_GET['post']) )\n\t\treturn;\n\n\tif( ea_disable_editor( $_GET['post'] ) ) {\n\t\tremove_post_type_support( 'page', 'editor' );\n\t}\n\n}\nadd_action( 'admin_head', 'ea_disable_classic_editor' );<\/code><\/pre>\n\n\n\n<p> <\/p>\n","protected":false},"excerpt":{"rendered":"<p>Using a plugin The Classic Editor plugin is great for disabling Gutenberg site-wide, but is not a good choice for selectively using it on certain pages. Gutenberg Ramp lets you disable Gutenberg on a per-post-type basis. You could use Gutenberg for posts, but keep the classic editor for pages. Using a filter We can use [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[17],"tags":[],"acf":[],"_links":{"self":[{"href":"https:\/\/hesmid.nl\/test\/wp-json\/wp\/v2\/posts\/13355"}],"collection":[{"href":"https:\/\/hesmid.nl\/test\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/hesmid.nl\/test\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/hesmid.nl\/test\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/hesmid.nl\/test\/wp-json\/wp\/v2\/comments?post=13355"}],"version-history":[{"count":1,"href":"https:\/\/hesmid.nl\/test\/wp-json\/wp\/v2\/posts\/13355\/revisions"}],"predecessor-version":[{"id":13356,"href":"https:\/\/hesmid.nl\/test\/wp-json\/wp\/v2\/posts\/13355\/revisions\/13356"}],"wp:attachment":[{"href":"https:\/\/hesmid.nl\/test\/wp-json\/wp\/v2\/media?parent=13355"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/hesmid.nl\/test\/wp-json\/wp\/v2\/categories?post=13355"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/hesmid.nl\/test\/wp-json\/wp\/v2\/tags?post=13355"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}