Skip to content

Instantly share code, notes, and snippets.

@sareiodata
Created October 26, 2016 11:54
Show Gist options
  • Save sareiodata/49b6a74c131c138ce9aa83a6fb53e4ac to your computer and use it in GitHub Desktop.
Save sareiodata/49b6a74c131c138ce9aa83a6fb53e4ac to your computer and use it in GitHub Desktop.
load a template for a particular URL
// http://wordpress.stackexchange.com/questions/9870/how-do-you-create-a-virtual-page-in-wordpress
add_action( 'init', 'frugal_add_rewrite_rule' );
function frugal_add_rewrite_rule()
{
add_rewrite_rule( 'budget$', 'index.php?budget=1', 'top' );
}
add_filter( 'query_vars', 'frugal_query_vars' );
function frugal_query_vars( $query_vars )
{
$query_vars[] = 'budget';
return $query_vars;
}
add_action( 'parse_request', 'frugal_parse_request' );
function frugal_parse_request( &$wp )
{
if ( array_key_exists( 'budget', $wp->query_vars ) ) {
include 'budget-template.php';
exit();
}
return;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment