Skip to content

Instantly share code, notes, and snippets.

@neverything
Created March 29, 2014 22:09
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 neverything/9863845 to your computer and use it in GitHub Desktop.
Save neverything/9863845 to your computer and use it in GitHub Desktop.
Remove parent theme page templates in child theme from required-foundation theme
<?php
/**
* Remove parent theme Page Templates
*/
$_templates_to_remove = array();
function remove_template( $files_to_delete = array() ){
global $_templates_to_remove;
if ( is_scalar( $files_to_delete ) )
$files_to_delete = array( $files_to_delete );
$_templates_to_remove = array_unique( array_merge( $_templates_to_remove, $files_to_delete ) );
add_action('admin_print_footer_scripts', '_remove_template_footer_scripts');
}
function _remove_template_footer_scripts() {
global $_templates_to_remove;
if ( ! $_templates_to_remove )
return;
?>
<script type="text/javascript">
jQuery(function($) {
var tpls = <?php echo json_encode( $_templates_to_remove ); ?>;
$.each(tpls, function(i, tpl) {
$('select[name="page_template"] option[value="'+ tpl +'"]').remove();
});
});
</script>
<?php
}
function remove_parent_templates() {
remove_template(
array(
'page-templates/full-width-page.php',
'page-templates/left-nav-page.php',
'page-templates/left-sidebar-page.php',
'page-templates/off-canvas-page.php',
)
);
}
add_action('admin_head-post.php', 'remove_parent_templates');
add_action('admin_head-post-new.php', 'remove_parent_templates');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment