Skip to content

Instantly share code, notes, and snippets.

@ninnypants
Created October 27, 2011 17:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ninnypants/1320187 to your computer and use it in GitHub Desktop.
Save ninnypants/1320187 to your computer and use it in GitHub Desktop.
Add rewrite rules to theme.
<?php
## Rewrite rules
add_filter( 'page_rewrite_rules','gcc_insert_rewrite_rules' );
add_filter( 'query_vars','gcc_insert_query_vars' );
add_action( 'wp_loaded','gcc_flush_rules' );
// flush_rules() if our rules are not yet included
function gcc_flush_rules(){
$rules = get_option( 'rewrite_rules' );
if ( ! isset( $rules['(edit-location)/(.*)$'] ) ) {
global $wp_rewrite;
$wp_rewrite->flush_rules();
}
}
// Adding a new rule
function gcc_insert_rewrite_rules( $rules ){
$newrules = array();
$newrules['(edit-location)/(.*)$'] = 'index.php?pagename=$1&location_name=$2';
return $newrules + $rules;
}
// Adding the id var so that WP recognizes it
function gcc_insert_query_vars( $vars ){
array_push($vars, 'location_name');
return $vars;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment