Created
November 15, 2012 14:56
-
-
Save takien/4079024 to your computer and use it in GitHub Desktop.
WordPress Custom Rewrite Rule
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
/** | |
* 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