/ /

Enable the Classic Editor in WordPress

This tutorial will guide you on how to use the provided code snippet to enable the Classic Editor for specific post types in WordPress. You can use this code as a standalone plugin or add it to FluentSnippets.

Introduction

This code selectively disables the Gutenberg (Block) Editor for specified post types and reverts to the Classic Editor for those post types. This is useful if you prefer using the Classic Editor for certain content types while using the Block Editor for others.

Full Code

<?php
/*
Plugin Name: Custom Classic Editor
Description: Enable the Classic Editor for specific post types while keeping the Block Editor for others.
Version: beta-0.0.1
Author: Muhammad Imanudin
Author URI: https://teman.web.id
Note: Currently (22-07-2024), you don't need to install the "Classic Editor" plugin because its functionality is still in the core.
*/

// Function to selectively disable the Gutenberg editor for specified post types
function custom_classic_editor_for_post_types($use_block_editor, $post) {
    // Array of post types to use the Classic Editor
    $classic_editor_post_types = array('page', 'custom_post_type'); // Add your custom post types here

    // Check if the current post type is in the array
    if (in_array($post->post_type, $classic_editor_post_types)) {
        // Disable the Gutenberg editor
        return false;
    }

    // Use the Block Editor for other post types
    return $use_block_editor;
}
add_filter('use_block_editor_for_post', 'custom_classic_editor_for_post_types', 10, 2);

Using the Code as a Standalone Plugin

Step 1: Create a New Plugin Folder

  1. Access your WordPress site’s FTP or file manager.
  2. Navigate to wp-content/plugins/.
  3. Create a new folder named custom-classic-editor.

Step 2: Create the Plugin File

  1. Inside the new folder, create a new file named custom-classic-editor.php.
  2. Paste the provided PHP code into this file.

Step 3: Activate the Plugin

  1. Go to your WordPress dashboard.
  2. Navigate to Plugins > Installed Plugins.
  3. Find “Custom Classic Editor” in the list and activate it.

Step 4: Configure Post Types

  1. Edit the plugin file if you want to add or remove post types.
  2. Locate the line:
   $classic_editor_post_types = array('page', 'custom_post_type');
  1. Add or remove post types as needed within the array.

Using the Code with FluentSnippets

Step 1: Install and Activate FluentSnippets

  1. Install FluentSnippets from the WordPress plugin directory if you haven’t already.
  2. Activate the plugin from the Plugins page.

Step 2: Add the Code Snippet

  1. Go to FluentSnippets > New Snippet in your dashboard.
  2. Select “Functions PHP” as the snippet type.
  3. Paste the provided PHP code into the code editor area.

Step 3: Configure and Activate the Snippet

  1. Give your snippet a name, e.g., “Custom Classic Editor”.
  2. Set the snippet to load on the admin side.
  3. Click “Save and Activate” to enable the snippet.

Step 4: Configure Post Types

  1. Edit the snippet if you need to change the post types.
  2. Update the $classic_editor_post_types array with your desired post types.

Understanding the Code

  • Plugin Header: Provides metadata about the plugin.
  • Function custom_classic_editor_for_post_types:
  • Parameters:
    • $use_block_editor: A boolean indicating whether the Block Editor is used.
    • $post: The post object.
  • Logic:
    • Checks if the current post type is in the $classic_editor_post_types array.
    • If yes, returns false to disable the Block Editor.
    • Otherwise, returns the original $use_block_editor value.

Configuration and Customization

  • Post Types: Ensure you replace 'custom_post_type' with your actual custom post type names.
  • Testing: After activation, create or edit posts of the specified types to ensure the Classic Editor is enabled.

Troubleshooting

  • Misspelled Post Types: Double-check the post type names for accuracy.
  • Compatibility: Verify that the code works with your version of WordPress.
  • Backup: Always backup your site before making code changes.

Conclusion

By following these steps, you can easily manage which post types use the Classic Editor and which use the Block Editor in WordPress. This flexibility allows you to tailor the editor experience to your workflow preferences.