Created
October 27, 2011 17:20
-
-
Save ninnypants/1320187 to your computer and use it in GitHub Desktop.
Add rewrite rules to theme.
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 | |
## 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