Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

After an intense research without finding the proper answer I decided to ask my question here.

I need to add some rewrite rules when activating a plugin in WordPress without existing custom rules being deleted. Example: if I add rules for plugin A, they are written into .htaccess (inside the WordPress block). But if I activate another plugin B which also has custom rewrite rules, then the rules of plugin A are overwritten by the rules of plugin B.

How I add the rules:

register_activation_hook(__FILE__, 'activatemyplugin');

function activatemyplugin() {
   add_rewrite_rule('pdf/([^/]*)$', plugins_url('pdfexport') . '/out/$1', 'top');

On deactivation of A or B, all custom rules (of A and B) are removed (replaced by default rules).

function deactivatemyplugin() {

How can I add and delete specific rewrite rules, so that previously added rules remain?

Every help is appreciated. Thanks in advance.

share|improve this question

migrated from stackoverflow.com Jul 19 '11 at 10:39

This question came from our site for professional and enthusiast programmers.

Your Answer


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