最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

functions - Hide WYSIWYG editor on certain templates

matteradmin6PV0评论

I hope the title makes sense. I currently want to hide the default WYSIWYG editor on some of the pages but display it on others.

Is there a filter or a hook for the functions file?

I hope the title makes sense. I currently want to hide the default WYSIWYG editor on some of the pages but display it on others.

Is there a filter or a hook for the functions file?

Share Improve this question asked Oct 11, 2016 at 19:33 kcroake88kcroake88 232 silver badges6 bronze badges
Add a comment  | 

2 Answers 2

Reset to default 5

I hope I understood your question right.

The following code will remove the editor from the pages using particular templates:

<?php

function wpse242371_remove_editor_from_some_pages()
{
    global $post;

    if( ! is_a($post, 'WP_Post') ) {
        return;
    }


    /* basename is used for templates that are in the subdirectory of the theme */
    $current_page_template_slug = basename( get_page_template_slug($post_id) );

    /* file names of templates to remove the editor on */
    $excluded_template_slugs = array(
        'tmp_file_one.php',
        'tmp_file_two.php',
        'tmp_file_three.php'
    );

    if( in_array($current_page_template_slug, $excluded_template_slugs) ) {
        /* remove editor from pages */
        remove_post_type_support('page', 'editor');
        /* if needed, add posts or CPTs to remove the editor on */
        // remove_post_type_support('post', 'editor');
        // remove_post_type_support('movies', 'editor');
    }

}

add_action('admin_enqueue_scripts', 'wpse242371_remove_editor_from_some_pages');
remove_post_type_support( 'page', 'editor' );

You can use it in several ways, a checkbox in the page would be nice, which if checked will hide the editor.

For more info > https://codex.wordpress/Function_Reference/remove_post_type_support

Post a comment

comment list (0)

  1. No comments so far