Skip to content

Instantly share code, notes, and snippets.

@markoheijnen
Created April 10, 2012 23:36
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 markoheijnen/2355637 to your computer and use it in GitHub Desktop.
Save markoheijnen/2355637 to your computer and use it in GitHub Desktop.
Create a WordPress page without a database entry
<?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