2

The answer to this question is working great but I want to exclude the editor also when other templates are used. Can you please tell me how to extend the code to make this work with more than one template?

2 Answers 2

8

Yes, try this :

function remove_editor() {
    if (isset($_GET['post'])) {
        $id = $_GET['post'];
        $template = get_post_meta($id, '_wp_page_template', true);
        switch ($template) {
            case 'template_01.php':
            case 'template_02.php':
            case 'template_03.php':
            case 'template_04.php':
            // the below removes 'editor' support for 'pages'
            // if you want to remove for posts or custom post types as well
            // add this line for posts:
            // remove_post_type_support('post', 'editor');
            // add this line for custom post types and replace 
            // custom-post-type-name with the name of post type:
            // remove_post_type_support('custom-post-type-name', 'editor');
            remove_post_type_support('page', 'editor');
            break;
            default :
            // Don't remove any other template.
            break;
        }
    }
}
add_action('init', 'remove_editor');

Change the 'template_01.php' ... 'template_04.php' with your template names and if you want you can add more template names by adding more cases.
e.g.

case 'template_05.php':


However, the above code and the code from the answer requires you to first set the page templates from the page edit screen.
I hope this helps and clears how this works.

1
  • You're most welcome :) Feb 11, 2017 at 11:09
0

Remove editor for pages chosen in custom settings, working with ACF plugin Firstly

/*
 * Add additional settings menu related with ACF plugin
 */
if ( function_exists( 'acf_add_options_page' ) ) {
    acf_add_options_page( array(
        'page_title' => 'Add. settings of Theme',
        'menu_title' => 'Add. settings',
        'menu_slug'  => 'theme-general-settings',
        'capability' => 'edit_posts',
        'redirect'   => false
    ) );

next step is to create custom fields with relation to pages in ACF plugin and in the final

/*
 * Remove editor for pages chosen in custom settings, working with ACF plugin
 */
function ogate_remove_editor() {
    $pages_without_editor = get_field('pages', 'option');
    if (isset($_GET['post'])) {
        $id = $_GET['post'];
        $template = get_post_meta($id, '_wp_page_template', true);
        if(!empty($pages_without_editor)) {
            foreach ( $pages_without_editor as $single ) {
                $my_template = get_post_meta($single->ID, '_wp_page_template', true);
                $template == $my_template ?
                    remove_post_type_support('page', 'editor') : false;
            }
        }
    }
}
add_action('init', 'ogate_remove_editor');

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.