Created
February 12, 2011 18:41
-
-
Save roelven/823973 to your computer and use it in GitHub Desktop.
WP rewrites
This file contains hidden or 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
// In functions.php: | |
// Get the existing Wordpress rewrite rules, usage: print_r(rv_get_rewrite_urls()); | |
function rv_get_rewrite_urls() { | |
global $wp_rewrite; | |
return $wp_rewrite->wp_rewrite_rules(); | |
} | |
// Flush rewrite rules, trigger on plugin activation | |
function rv_rewrite_flush() { | |
global $wp_rewrite; | |
$wp_rewrite->flush_rules(); | |
} | |
// Add support for reading $_GET like URL variables, inspired by: | |
// http://youngdutchdesign.com/rewrite-multiple-get-variables-for-wordpress-plugins | |
function rv_newsletter_var($public_query_vars) { | |
$public_query_vars[] = 'rv_urlvar'; | |
return $public_query_vars; | |
} | |
// Add a rewrite rule | |
// Used it here for /newsletter on a site, can be for anything! | |
function rv_rewrite_newsletter() { | |
add_rewrite_rule('newsletter/([^/]+)/?$', 'index.php?pagename=newsletter&rv_urlvar=$matches[1]','top'); | |
} | |
// Add support for $_GET like URI variables: (use /newsletter/yourvariable) | |
//add_action('init', 'rv_rewrite_newsletter'); | |
//add_filter('query_vars', 'rv_newsletter_var'); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment