Skip to content

Instantly share code, notes, and snippets.

@sadikyalcin
Created May 17, 2019 13:23
Show Gist options
  • Save sadikyalcin/7c5ff7fe71cae959bf4a0fe07ab89600 to your computer and use it in GitHub Desktop.
Save sadikyalcin/7c5ff7fe71cae959bf4a0fe07ab89600 to your computer and use it in GitHub Desktop.
Register custom query vars and template hierarchy re-write to load a specific template for a post type
function prefix_register_query_var( $vars ) {
$vars[] = 'eb_id';
$vars[] = 'eb_t';
return $vars;
}
add_filter( 'query_vars', 'prefix_register_query_var' );
function prefix_url_rewrite_templates() {
if ( get_query_var( 'eb_id' ) ) {
add_filter( 'template_include', function() {
return get_template_directory() . '/events-single.php'; // your template
});
}
}
add_action( 'template_redirect', 'prefix_url_rewrite_templates' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment