最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

templates - Remove Content edit box from ALL pages (not posts)

programmeradmin4浏览0评论

I've found several function examples online that remove the content editor based on the template of the page. The issue I am having is that the content is not a post, but the wordpress generic "page" functionality.

I want to remove the main content editor from all pages - not custom post type, just standard WP page.

I have tried the code below. However I believe the edit on the templat-file part is incorrect because this is not a post type:

add_action( 'admin_init', 'hide_editor' );

function hide_editor() {
    // Get the Post ID.
    $post_id = $_GET['post'] ? $_GET['post'] : $_POST['post_ID'] ;
    if( !isset( $post_id ) ) return;

    // Get the name of the Page Template file.
    $template_file = get_post_meta($post_id, '_wp_page_template', true);

    if($template_file == 'page.php'){
        remove_post_type_support('page', 'editor');
    }
}

How else can I do this to all pages ?

I've found several function examples online that remove the content editor based on the template of the page. The issue I am having is that the content is not a post, but the wordpress generic "page" functionality.

I want to remove the main content editor from all pages - not custom post type, just standard WP page.

I have tried the code below. However I believe the edit on the templat-file part is incorrect because this is not a post type:

add_action( 'admin_init', 'hide_editor' );

function hide_editor() {
    // Get the Post ID.
    $post_id = $_GET['post'] ? $_GET['post'] : $_POST['post_ID'] ;
    if( !isset( $post_id ) ) return;

    // Get the name of the Page Template file.
    $template_file = get_post_meta($post_id, '_wp_page_template', true);

    if($template_file == 'page.php'){
        remove_post_type_support('page', 'editor');
    }
}

How else can I do this to all pages ?

Share Improve this question asked Feb 4, 2015 at 12:08 FrancescaFrancesca 3052 gold badges7 silver badges16 bronze badges 1
  • Pages are posts, they are posts of type page, for the most part they're no different to other custom post types, and they're stored the same way in the database – Tom J Nowell Commented Feb 4, 2015 at 12:21
Add a comment  | 

1 Answer 1

Reset to default 4

Found the following solution which works to remove the content editor from all "page" content. Just chuck it in the functions.php file

add_action('admin_init', 'remove_textarea');

    function remove_textarea() {
            remove_post_type_support( 'page', 'editor' );
    }
发布评论

评论列表(0)

  1. 暂无评论