Created
March 10, 2017 14:04
-
-
Save Clorith/5a5d518ab2d7a0ad059542e040ba5dda to your computer and use it in GitHub Desktop.
Override page templates in WordPress
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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