Skip to content

Instantly share code, notes, and snippets.

@Rupashdas
Last active October 23, 2023 05:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Rupashdas/4036322a5577be84cc9c677b46d21a4f to your computer and use it in GitHub Desktop.
Save Rupashdas/4036322a5577be84cc9c677b46d21a4f to your computer and use it in GitHub Desktop.
<?php
function get_page_id_by_template($page_template_filename){
$pages = get_pages( array(
'meta_key' => '_wp_page_template',
'meta_value' => $page_template_filename
) );
$pageIds = array();
foreach($pages as $page){
$pageId = $page->ID;
array_push($pageIds, $pageId);
}
return $pageIds;
}
function croft_hide_editor() {
$page_id = isset($_GET['post']) ? $_GET['post'] : '' ;
if($page_id != ""){
$disabled_IDs = array();
$croft_page_templates = array( 'template-home.php');
foreach($croft_page_templates as $croft_page_template){
$pageIds = get_page_id_by_template('templates/'.$croft_page_template);
foreach($pageIds as $pageId){
array_push($disabled_IDs, $pageId);
}
}
if (in_array($page_id, $disabled_IDs)) {
remove_post_type_support('page', 'editor');
}
}
}
add_action( 'admin_init', 'croft_hide_editor' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment