Skip to content

Instantly share code, notes, and snippets.

@agustinprosperi
Last active August 25, 2017 09:43
Show Gist options
  • Save agustinprosperi/6cfa939276da46ab4113 to your computer and use it in GitHub Desktop.
Save agustinprosperi/6cfa939276da46ab4113 to your computer and use it in GitHub Desktop.
Remove content editor for some pages or posts by id or template name, wordpress
<?php
// sitioPageOptionID
function sitioPageOptionID(){
global $opgd;
if( empty($opgd) || empty($opgd->post_count) ){
//return 6;
$opgd = new WP_Query(array(
'post_type' => 'page',
'meta_key' => '_wp_page_template',
'meta_value' => 'template-options-gd.php',
'post_status' => get_post_stati(),
//'suppress_filters' => 1
));
}
return ( !empty( $opgd->post_count ) )? $opgd->posts[0]->ID: 0;
}
//remove/hide content editor for some pages or posts
add_action('admin_init', 'remove_editor_by_pages_id');
function remove_editor_by_pages_id() {
// if we are on edit post or page
if (!empty($_GET['post'])) {
$post_id = $_GET['post'];
} elseif (!empty($_POST['post_ID'])) {
$post_id = $_POST['post_ID'];
} else return;
// your wanted id's here - if you don't want use this option leave the array empty
$idsToExclude = array( sitioPageOptionID() );
$idsToExclude = apply_filters("tt_postids_to_remove_editor", $idsToExclude);
// templates name - if you don't want use this option leave the array empty
$templatesToRemove = array(
'template-contacto.php',
'template-homepage.php',
// 'template-formacion.php',
);
$templatesToRemove = apply_filters("tt_templates_to_remove_editor", $templatesToRemove);
// or if certain template
$template_file = get_post_meta($post_id, '_wp_page_template', TRUE);
if ( in_array($post_id, $idsToExclude) || in_array($template_file, $templatesToRemove) ) {
$post = get_post( $post_id );
remove_post_type_support( $post->post_type, 'editor' );
}
}
@willyfc
Copy link

willyfc commented Jul 21, 2016

Te creés muy sabroso con tu cuenta de Git, no?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment