Created
April 9, 2014 09:07
-
-
Save danpecher/10244879 to your computer and use it in GitHub Desktop.
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 | |
/* | |
* In template | |
*/ | |
get_query_var($var); | |
/* | |
* functions.php | |
*/ | |
add_filter('rewrite_rules_array','wp_insertMyRewriteRules'); | |
add_filter('query_vars','wp_insertMyRewriteQueryVars'); | |
add_filter('init','flushRules'); | |
// Remember to flush_rules() when adding rules | |
function flushRules(){ | |
global $wp_rewrite; | |
$wp_rewrite->flush_rules(); | |
} | |
// Adding a new rule | |
function wp_insertMyRewriteRules($rules) | |
{ | |
$newrules = array(); | |
$newrules['gallery/(.+)'] = 'index.php?pagename=gallery&pid=$matches[1]'; | |
$finalrules = $newrules + $rules; | |
return $finalrules; | |
} | |
// Adding the var so that WP recognizes it | |
function wp_insertMyRewriteQueryVars($vars) | |
{ | |
array_push($vars, 'pid'); | |
return $vars; | |
} | |
//Stop wordpress from redirecting | |
remove_filter('template_redirect', 'redirect_canonical'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment