Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save swooningfish/b2d3a1a5eb5750e7a2034b0c18f43bd2 to your computer and use it in GitHub Desktop.
Save swooningfish/b2d3a1a5eb5750e7a2034b0c18f43bd2 to your computer and use it in GitHub Desktop.

Revisions

  1. @atomtigerzoo atomtigerzoo renamed this gist Jul 16, 2015. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  2. @atomtigerzoo atomtigerzoo renamed this gist Jul 16, 2015. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  3. @atomtigerzoo atomtigerzoo revised this gist Jul 16, 2015. 1 changed file with 38 additions and 20 deletions.
    58 changes: 38 additions & 20 deletions hide-editor.php
    Original file line number Diff line number Diff line change
    @@ -1,27 +1,45 @@
    <?php

    /**
    * Hide editor on specific pages.
    *
    * Hide the main editor on specific pages
    */
    add_action( 'admin_init', 'hide_editor' );
    define('EDITOR_HIDE_PAGE_TITLES', json_encode(array()));
    define('EDITOR_HIDE_PAGE_TEMPLATES', json_encode(array('template-cars.php')));


    function hide_editor() {
    // Get the Post ID.
    $post_id = $_GET['post'] ? $_GET['post'] : $_POST['post_ID'] ;
    if( !isset( $post_id ) ) return;
    /**
    * Hide the main editor on defined pages
    *
    * You can choose between page titles or page templates. Just set them
    * accordingly like this:
    *
    * define('EDITOR_HIDE_PAGE_TITLES', json_encode(array('Home', 'Some post archive', 'Some Listing')));
    * define('EDITOR_HIDE_PAGE_TEMPLATES', json_encode(array('template-of-something.php', 'archive-customposttype.php')));
    *
    *
    * @global string $pagenow
    * @return void
    */
    function atz_hide_editor() {
    global $pagenow;
    if(!('post.php' == $pagenow)){
    return;
    }

    // Get the Post ID.
    $post_id = filter_input(INPUT_GET, 'post') ? filter_input(INPUT_GET, 'post') : filter_input(INPUT_POST, 'post_ID');
    if(!isset($post_id)) {
    return;
    }

    // Hide the editor on the page titled 'Homepage'
    $homepgname = get_the_title($post_id);
    if($homepgname == 'Homepage'){
    remove_post_type_support('page', 'editor');
    }
    // Hide the editor on the page titled 'Homepage'
    if(in_array(get_the_title($post_id), json_decode(EDITOR_HIDE_PAGE_TITLES))) {
    remove_post_type_support('page', 'editor');
    }

    // Hide the editor on a page with a specific page template
    // Get the name of the Page Template file.
    $template_file = get_post_meta($post_id, '_wp_page_template', true);
    // Hide the editor on a page with a specific page template
    $template_filename = get_post_meta($post_id, '_wp_page_template', true);

    if($template_file == 'my-page-template.php'){ // the filename of the page template
    remove_post_type_support('page', 'editor');
    }
    if(in_array($template_filename, json_decode(EDITOR_HIDE_PAGE_TEMPLATES))) {
    remove_post_type_support('page', 'editor');
    }
    }
    add_action('admin_init', 'atz_hide_editor');
  4. @ramseyp ramseyp created this gist Nov 12, 2012.
    27 changes: 27 additions & 0 deletions hide-editor.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,27 @@
    <?php

    /**
    * Hide editor on specific pages.
    *
    */
    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;

    // Hide the editor on the page titled 'Homepage'
    $homepgname = get_the_title($post_id);
    if($homepgname == 'Homepage'){
    remove_post_type_support('page', 'editor');
    }

    // Hide the editor on a page with a specific page template
    // Get the name of the Page Template file.
    $template_file = get_post_meta($post_id, '_wp_page_template', true);

    if($template_file == 'my-page-template.php'){ // the filename of the page template
    remove_post_type_support('page', 'editor');
    }
    }