Created
December 29, 2015 09:23
-
-
Save vivianspencer/f5432b27350e6e444c38 to your computer and use it in GitHub Desktop.
Wordpress Virtual Page
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 | |
function my_rewrite_init() | |
{ | |
add_rewrite_rule( 'your-desired-path', 'index.php?your-query-var=1', 'top' ); | |
} | |
add_action( 'init', 'my_rewrite_init' ); | |
function my_rewrite_query_vars( $query_vars ) | |
{ | |
$query_vars[] = 'your-query-var'; | |
return $query_vars; | |
} | |
add_action( 'query_vars', 'my_rewrite_query_vars' ); | |
function my_rewrite_redirect() | |
{ | |
global $wp_query; | |
if ( array_key_exists( 'your-query-var', $wp_query->query_vars ) ) { | |
include( 'your-desired-template.php' ); | |
exit(); | |
} | |
return; | |
} | |
add_action( 'template_redirect', 'my_rewrite_redirect' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment