Skip to content

Instantly share code, notes, and snippets.

@benvisser
Created October 11, 2012 02:13
Show Gist options
  • Save benvisser/3869755 to your computer and use it in GitHub Desktop.
Save benvisser/3869755 to your computer and use it in GitHub Desktop.
Sample Wordpress rewrite rule filters
///////////////////////////////////
// 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