开发者

Remove main editor from wordpress edit page screen

开发者 https://www.devze.com 2022-12-25 16:18 出处:网络
Anyone know of a way to remove the main editor from the page edit screen? And not just with css. I\'ve added a few other meta boxes with the tinymce and they collide with the main one.

Anyone know of a way to remove the main editor from the page edit screen? And not just with css. I've added a few other meta boxes with the tinymce and they collide with the main one.

I have a class that removes other meta boxes from the edit screen, but I cant get rid of the main editor this way. I've tried to add 'divpostrich' and 'divpost' to the array in the class (but with no luck):

class removeMetas{
    public function __construct(){
        add_action('do_meta_boxes', array($this, 'removeMetaBoxes'), 10, 3);
    }

    public function removeMetaBoxes($type, $context, $post){
        /**
         * usages
         * remove_meta_box($id, $page, $开发者_JS百科context)
         * add_meta_box($id, $title, $callback, $page, $context = 'advanced', $priority = 'default')
         */
        $boxes = array( 'slugdiv', 'postexcerpt', 'passworddiv', 'categorydiv',
                        'tagsdiv', 'trackbacksdiv', 'commentstatusdiv', 'commentsdiv',
                        'authordiv', 'postcustom');

        foreach ($boxes as $box){
            foreach (array('link', 'post', 'page') as $page){
                foreach (array('normal', 'advanced', 'side') as $context){
                    remove_meta_box($box, $type, $context);
                }
            }
        }
    }
}

$removeMetas = new removeMetas();

I have also tried removing the 'divpostrich' with jquery. But cant figure out where to put the js for it to work. When I remove the 'postdivrich' in the browser with firebug - my remaining tinymce fields work perfect.

Any ideas?


There is built in WP support for this so you don't have to fiddle directly with the globals and ensure forwards compatibility if they ever change how features are handled. The WP Core code does pretty much the exact same logic as @user622018 answer however

function remove_editor() {
  remove_post_type_support('page', 'editor');
}
add_action('admin_init', 'remove_editor');


What you are looking for is the global $_wp_post_type_features array.

Below is a quick example of how it can be used

function reset_editor()
{
     global $_wp_post_type_features;

     $post_type="page";
     $feature = "editor";
     if ( !isset($_wp_post_type_features[$post_type]) )
     {

     }
     elseif ( isset($_wp_post_type_features[$post_type][$feature]) )
     unset($_wp_post_type_features[$post_type][$feature]);
}

add_action("init","reset_editor");


Add the following code to your functions.

function remove_editor_init() {
if ( is_admin() ) {
    $post_id = 0;
    if(isset($_GET['post'])) $post_id = $_GET['post'];
    $template_file = get_post_meta($post_id, '_wp_page_template', TRUE);
    if ($template_file == 'page-home.php') {
        remove_post_type_support('page', 'editor');
    }
}
}
add_action( 'init', 'remove_editor_init' );


Couldn't you just disable the TinyMCE editor, leaving the HTML editor, as your meta boxes are colliding with it? :)


To disable the editor you will need to edit your wp-config.php file and add this line to the top:

define('DISALLOW_FILE_EDIT', true);
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号