I'm using Milo's answer to add a Rewrite Endpoint as part of my plugin.

Is there a straight-forward way to remove a Rewrite Rule upon deactivation?

I found this snippet but I'd expect a "remove_rewrite_endpoint" to match add_rewrite_endpoint

Also, how do I know what to look for in the rewrite rules list when add_rewrite_endpoint was used to add the rule?

1 Answer 1


All you need is flush the rewrite rules on deactivation. For example, in the main plugin file:

register_deactivation_hook( __FILE__, function() {
  • 1
    How does it know which rewrite rule(s) to remove?
    – Meglio
    Commented Jul 29, 2015 at 4:34
  • Flushing removes all rewrite rules with no distinction. Then they are rebuilt again from scratch.
    – cybmeta
    Commented Jul 30, 2015 at 15:53
  • Are they rebuilt on the fly bit by bit as needed, or are they rebuilt all at once as soon as needed?
    – Meglio
    Commented Aug 1, 2015 at 4:56
  • I'm not fully sure but as far I understand, they are all rebuilt at once in next page load and stored in database until they are flushed again. This database operation is the reason why flushing rewrite rules must be used carefully, only one time if is needed, never on every page load. For example, in this answer is used only on plugin activation because the plugin affect rewrite rules and need to be flushed.
    – cybmeta
    Commented Aug 1, 2015 at 10:56
  • 1
    Yes, on init action hook preferably. You may be interested in a question I made some time ago where I learn that: Rewrite rules go away.
    – cybmeta
    Commented Aug 5, 2015 at 12:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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