Last active
August 29, 2015 14:24
-
-
Save nielsvr/a0ae56c0b267b29a0cbd to your computer and use it in GitHub Desktop.
Custom rewrite for WordPress with custom template
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 | |
// enables you to use example url "/showcase/case-title" and pushes it to "single-showcases.php" template for rendering | |
function mu_custom_rewrites() { | |
global $wp; | |
$wp->add_query_var('case'); | |
add_rewrite_tag('%case%', '([^/]+)', 'case='); | |
add_permastruct('showcase', '/showcase/%case%/', false); | |
} | |
add_action('init', 'my_custom_rewrites', 10, 0); | |
function my_parse_query() { | |
global $wp_query; | |
if (get_query_var('case') != '') { | |
add_action('template_redirect', 'my_template_redirect'); | |
} | |
} | |
add_filter('parse_query','my_parse_query'); | |
function my_template_redirect() { | |
global $template; | |
if (get_query_var('case') != '') { | |
$template = get_query_template('single-showcases'); | |
include ($template); | |
exit(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment