Skip to content

Instantly share code, notes, and snippets.

@BinaryMoon
Last active August 16, 2019 20:33
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save BinaryMoon/f5094960f888b16d29696dcca63e54c5 to your computer and use it in GitHub Desktop.
Save BinaryMoon/f5094960f888b16d29696dcca63e54c5 to your computer and use it in GitHub Desktop.
Set the classic editor block as the default block when creating a new post.
<?php
/**
* Plugin Name: Classic Editor First
* Plugin URI: https://prothemedesign.com
* Description: Set the default post block to use the classic editor block.
* Author: Ben Gillbanks
* Version: 1.0
* Author URI: https://prothemedesign.com
*/
/**
* Modify post type arguments to add default post type templates.
*
* @param array $args The default post type arguments.
* @param string $post_type The post type for the current request.
* @return array Modified arguments including the new template properties.
*/
function my_theme_post_type_arguments( $args, $post_type ) {
// Only apply changes to the specified post type.
// You could remove this to apply the change to all post types, or change it
// to filter selected post types.
if ( 'post' !== $post_type ) {
return $args;
}
/**
* Adds a template property to the specified post type arguments.
*
* You can get a list of available blocks by entering the following js
* command in the console window in your browser.
* wp.blocks.getBlockTypes()
*
* The output of this command also shows the available attributes for setting defaults.
*
* @var array
*/
$args['template'] = array(
array( 'core/freeform' ),
);
return $args;
}
add_filter( 'register_post_type_args', 'my_theme_post_type_arguments', 20, 2 );
@webmandesign
Copy link

Nice, simple code. Thanks!
Though I think there is $args missing in first return. Line 23 should probably be:

if ( 'post' !== $post_type ) {
	return $args;
}

@BinaryMoon
Copy link
Author

Ah ha - good catch. Thanks for pointing that out. I've updated the code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment