How to Set a Default WP Editor for a Custom Post Type

James Parsons by James Parsons Updated Feb 2nd, 2024 2 Comments

WordPress lets you switch between the Classic and Gutenberg editor, but this is a site-wide change. What if you want your regular posts to be in the Classic editor, and your custom posts in Gutenberg? Or vice-versa?

I wrote this functions.php snippet to come to the rescue.

A requirement for this snippet to work is that you install the Classic Editor WordPress plugin. Chances are good that you already have this plugin, as it's in the top 5 most downloaded plugins of all time.

Once you're ensured that plugin is installed, simply add this to your functions.php, taking care to swap out your_custom_post_type with the name of your custom post type.

/*
 * Set a default editor for a custom post type
 */ 

add_action('admin_menu', 'modify_new_post_link_for_custom_post_type', 999);

function modify_new_post_link_for_custom_post_type() {
    global $submenu;
    $post_type = 'your_custom_post_type'; // Change this to your custom post type
    $set_gutenberg = true; // true = Gutenberg, false = Classic editor
    if (isset($submenu['edit.php?post_type=' . $post_type])) {
        foreach ($submenu['edit.php?post_type=' . $post_type] as &$item) {
            if ($item[2] === 'post-new.php?post_type=' . $post_type) {
                if ($set_gutenberg) {
                    $item[2] .= '&classic-editor__forget';
                } else {
                    $item[2] .= '&classic-editor__forget&classic-editor';
                }
            }
        }
    }
}

For the $set_gutenberg section, this is set to "true" by default, which means it will load Gutenberg when you go to add a new custom post. If you want to turn off Gutenberg for your custom post type, set this to false.

What if I want to add this to more than one custom post type?

It's pretty easy to adapt this! You can tweak this line to add two custom post types:

$post_type = ['your_custom_post_type', 'another_post_type']; 

Cool, right? Drop me a comment if this helped you!

Related Code Snippets

Written by James Parsons

James Parsons is the founder and CEO of Content Powered, a premier content marketing agency that leverages nearly two decades of his experience in content marketing to drive business growth. Renowned for founding and scaling multi-million dollar eCommerce businesses through strategic content marketing, James has become a trusted voice in the industry, sharing his insights in Search Engine Watch, Search Engine Journal, Forbes, Entrepreneur, Inc, and other leading publications. His background encompasses key roles across various agencies, contributing to the content strategies of major brands like eBay and Expedia. James's expertise spans SEO, conversion rate optimization, and effective content strategies, making him a pivotal figure in the industry.