WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm using www.domain.com/%POSTNAME%/CAR permalink structure (CAR is the variable i need to extract.

After adding the code to the functions.php the other wordpress url's stopped working (category, archives, pages) and now its showing 404 everywhere the only thing are working are posts.

This is the code:

 * create_custom_rewrite_rules()
 * Creates the custom rewrite rules.
 * return array $rules.

function create_custom_rewrite_rules() {
 global $wp_rewrite;

// Define custom rewrite tokens
 $rewrite_tag = '%exampletag%';

// Add the rewrite tokens
 $wp_rewrite->add_rewrite_tag( $rewrite_tag, '(.+?)', 'car=' );

// Define the custom permalink structure
 $rewrite_keywords_structure = $wp_rewrite->root . "%postname%/$rewrite_tag/";

// Generate the rewrite rules
 $new_rule = $wp_rewrite->generate_rewrite_rules( $rewrite_keywords_structure );

// Add the new rewrite rule into the global rules array
 $wp_rewrite->rules = $new_rule + $wp_rewrite->rules;

return $wp_rewrite->rules;

} // End create_custom_rewrite_rules()

 * add_custom_page_variables()
 * Add the custom token as an allowed query variable.
 * return array $public_query_vars.

function add_custom_page_variables( $public_query_vars ) {
 $public_query_vars[] = 'car';

return $public_query_vars;

} // End add_custom_page_variables()

function flush_rewrite_rules() {

global $wp_rewrite;



add_action( 'admin-init', 'flush_rewrite_rules' );
 add_action( 'generate_rewrite_rules', 'create_custom_rewrite_rules' );
 add_filter( 'query_vars', 'add_custom_page_variables' );

I have 0 plugins activated so the error is in the code. The only way i got category working was changing them from /category/categoryname to /category/category/%categoryname% but i have no way to change pages and archives to make them work. So that why i need help.


share|improve this question

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.