Skip to content

Instantly share code, notes, and snippets.

@danpecher
Created April 9, 2014 09:07
Show Gist options
  • Save danpecher/10244879 to your computer and use it in GitHub Desktop.
Save danpecher/10244879 to your computer and use it in GitHub Desktop.
<?php
/*
* In template
*/
get_query_var($var);
/*
* functions.php
*/
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['gallery/(.+)'] = 'index.php?pagename=gallery&pid=$matches[1]';
$finalrules = $newrules + $rules;
return $finalrules;
}
// Adding the var so that WP recognizes it
function wp_insertMyRewriteQueryVars($vars)
{
array_push($vars, 'pid');
return $vars;
}
//Stop wordpress from redirecting
remove_filter('template_redirect', 'redirect_canonical');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment