Advertisement
hendridm

Disable Gutenberg by Template (example)

Jul 4th, 2018
593
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.64 KB | None | 0 0
  1. /**
  2.   * Example of disabling Gutenberg by template
  3.   * @see https://www.billerickson.net/disabling-gutenberg-certain-templates/
  4.   */
  5.  
  6. add_filter( 'gutenberg_can_edit_post_type', 'disable_gutenberg_editor_by_template', 10, 2 );
  7.  
  8. function disable_gutenberg_editor_by_template( $can_edit, $post_type ) {
  9.  
  10.     if( !is_admin() || !isset( $_GET['post'] ) || !intval( $_GET['post'] ) ) return $can_edit;
  11.     $exclude_templates = get_option( 'my_array_of_post_types_to_disable' );
  12.     if( !$exclude_templates ) return $can_edit;
  13.  
  14.     $current_template = get_page_template_slug( $_GET['post'] );
  15.  
  16.     return !in_array( $current_template, $exclude_templates );
  17.  
  18. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement