Skip to content

Instantly share code, notes, and snippets.

@Clorith
Created March 10, 2017 14:04
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 Clorith/5a5d518ab2d7a0ad059542e040ba5dda to your computer and use it in GitHub Desktop.
Save Clorith/5a5d518ab2d7a0ad059542e040ba5dda to your computer and use it in GitHub Desktop.
Override page templates in WordPress
<?php
/*
* Override the template engine when it's looking for a themes templates files, and output our own one instead
*/
add_filter( 'page_template','maybe_hijack_page' );
function maybe_hijack_page( $template ) {
// Check the page ID and hijack if it's ID 50, this can be any conditional!
if ( get_the_ID() == 50 ) {
show_admin_bar( false );
$template = dirname( __FILE__ ) . '/public.php';
}
return $template;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment