Created
October 11, 2012 02:13
-
-
Save benvisser/3869755 to your computer and use it in GitHub Desktop.
Sample Wordpress rewrite rule filters
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
/////////////////////////////////// | |
// Rewrite Rules | |
/////////////////////////////////// | |
//rewrite rules | |
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['yourpage/(.+)'] = 'index.php?pagename=yourpage/&page=$matches[1]'; | |
$finalrules = $newrules + $rules; | |
return $finalrules; | |
} | |
// Adding the var so that WP recognizes it | |
function wp_insertMyRewriteQueryVars($vars) { | |
array_push($vars, 'page'); | |
return $vars; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment