Instantly share code, notes, and snippets.

Embed
What would you like to do?
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

This comment has been minimized.

webmandesign commented Sep 27, 2018

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

This comment has been minimized.

Owner

BinaryMoon commented Sep 27, 2018

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