0

It seems that the add_rewrite_rule works only if the permalink is set to non empty value in wp-admin/setting page. Isn't it?

Then once I set that value to /item/%post_id%, I got the rewrite rules like this through debugging:http://imgur.com/a/08nAU.

There are too many rules not necessary in my case, is it possible to remove that?

2

You can modify the global WP_Rewrite variable directly.

add_action('init', function(){

    global $wp_rewrite;

    echo "<pre>";
    var_dump($wp_rewrite);
    wp_die();
});

There are sevel properties you can adjust:

  • $wp_rewrite->permalink_structure
  • $wp_rewrite->use_trailing_slashes
  • $wp_rewrite->author_base
  • $wp_rewrite->search_base
  • $wp_rewrite->comments_base
  • $wp_rewrite->pagination_base
  • $wp_rewrite->comments_pagination_base
  • $wp_rewrite->feed_base
  • $wp_rewrite->front
  • $wp_rewrite->root
  • $wp_rewrite->index
  • $wp_rewrite->matches
  • $wp_rewrite->rules
  • $wp_rewrite->extra_rules
  • $wp_rewrite->extra_rules_top
  • $wp_rewrite->non_wp_rules
  • $wp_rewrite->extra_permastructs
  • $wp_rewrite->endpoints
  • $wp_rewrite->use_verbose_rules
  • $wp_rewrite->use_verbose_page_rules
  • $wp_rewrite->rewritecode
  • $wp_rewrite->rewritereplace
  • $wp_rewrite->queryreplace
  • $wp_rewrite->feeds

And alternate removal functions:

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.