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

Updated 02/02/2024, Posted 02/02/2024 by James Parsons James Parsons 0 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

Hi, I'm James Parsons! I founded Content Powered, a content marketing agency where I partner with businesses to help them grow through strategic content. With nearly twenty years of SEO and content marketing experience, I've had the joy of helping companies connect with their audiences in meaningful ways. I started my journey by building and growing several successful eCommerce companies solely through content marketing, and I love to share what I've learned along the way. You'll find my thoughts and insights in publications like Search Engine Watch, Search Engine Journal, Forbes, Entrepreneur, and Inc, among others. I've been fortunate to work with wonderful clients ranging from growing businesses to Fortune 500 companies like eBay and Expedia, and helping them shape their content strategies. My focus is on creating optimized content that resonates and converts. I'd love to connect – the best way to contact me is by scheduling a call or by email.