Created
November 22, 2018 08:33
-
-
Save deckerweb/e8f042d3d649cf4906f07e3643d2884e to your computer and use it in GitHub Desktop.
Disable Gutenberg except for “Frontpage” page - found via: https://codeshare.io/29Kj8K
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Disable Gutenberg by Default | |
* but let others easily override that by changing hook priority to 5 | |
* https://justnorris.com/how-to-dynamically-enable-gutenberg/ | |
*/ | |
add_filter( 'gutenberg_can_edit_post', '__return_false', 5 ); | |
add_filter( 'use_block_editor_for_post', '__return_false', 5 ); | |
// But enable Gutenberg in a page with title “Frontpage” | |
function maybe_load_gutenberg( $can_edit, $post ) { | |
$mypage = get_page_by_title( 'Frontpage' ); | |
// Enable Gutenberg | |
if ( $mypage->ID === $post->ID ) { | |
return true; | |
} | |
return $can_edit; | |
} | |
// Gutenberg >= 3.5 | |
add_filter( 'gutenberg_can_edit_post', 'maybe_load_gutenberg', 10, 2 ); | |
// WordPress >= 5.0 | |
add_filter( 'use_block_editor_for_post', 'maybe_load_gutenberg', 10, 2 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment