Skip to content

Instantly share code, notes, and snippets.

@takien
Created November 15, 2012 14:56
Show Gist options
  • Save takien/4079024 to your computer and use it in GitHub Desktop.
Save takien/4079024 to your computer and use it in GitHub Desktop.
WordPress Custom Rewrite Rule
/**
* WordPress Custom Rewrite Rule
* @author: takien
* @version: 1.0
* @url: http://takien.com
*/
function create_rewrite_rules() {
global $wp_rewrite;
$rewrite_tag = '%coba%';
$wp_rewrite->add_rewrite_tag( $rewrite_tag, '(.+?)', 'coba=' );
$rewrite_keywords_structure = $wp_rewrite->root . "coba/$rewrite_tag";
$new_rule = $wp_rewrite->generate_rewrite_rules( $rewrite_keywords_structure );
$wp_rewrite->rules = $new_rule + $wp_rewrite->rules;
return $wp_rewrite->rules;
}
function add_custom_page_variables( $public_query_vars ) {
$public_query_vars[] = 'coba';
return $public_query_vars;
}
add_action( 'generate_rewrite_rules', 'create_rewrite_rules' );
add_filter( 'query_vars', 'add_custom_page_variables' );
$coba = get_query_var('coba');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment