Created
April 10, 2012 23:36
-
-
Save markoheijnen/2355637 to your computer and use it in GitHub Desktop.
Create a WordPress page without a database entry
This file contains 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 | |
add_action( 'generate_rewrite_rules', 'specialpage_rewrite' ); | |
function specialpage_rewrite( $wp_rewrite ) { | |
$extra_rules = array( | |
'special-page/?$' => 'index.php?show_special_page=1', | |
); | |
$wp_rewrite->rules = $extra_rules + $wp_rewrite->rules; | |
} | |
add_filter( 'query_vars', 'specialpage_query_vars' ); | |
function specialpage_query_vars( $vars ) | |
{ | |
array_push($vars, 'show_special_page'); | |
return $vars; | |
} | |
add_filter( 'template_include', 'specialpage_switch_template' ); | |
function specialpage_switch_template( $template ) { | |
global $wp_query; | |
global $post; | |
if ( isset( $wp_query->query_vars['show_special_page'] ) && $wp_query->query_vars['show_special_page'] == '1' ) { | |
return TEMPLATEPATH.'/special-page.php'; | |
} | |
return $template; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment