flush_rewrite_rules not working on plugin deactivation, invalid URLs not showing 404

Have you tried delete_option(‘rewrite_rules’); on deactivate? I came across the following when investigating this problem and it did the trick for me: Typically you register post types on init. Some time after that, you get the deactivation action. A responsible plugin would remove its rewrite rules by flushing. However, it can’t undo the registration, so … Read more

Display CPT taxonomies as an archive page

You’re describing the default behaviour. Based on your code, you will have the following URLs: https://www.url.com/blog/addresses/ The archive of all Articles. https://www.url.com/blog/city/tunis/ The archive of all Articles assigned to the Tunis City. https://www.url.com/blog/addresses/article-title/ The single Article. If any of these URLs are returning a 404, you likely just need to flush your permalinks. This needs … Read more

WordPress keeps writing rewrite rules to .htaccess

I am not sure why this happens, but you can stop all write access to your .htaccess with a simple filter: add_filter( ‘flush_rewrite_rules_hard’, ‘__return_false’ ); Neither WordPress nor any plugins calling flush_rewrite_rules() will write something into the file now. Other methods to access and change the file will still work, for example insert_with_markers().

flexible rewrite ‘ramble’ URLs with WordPress

You shouldn’t use the htaccess instead you should use the WordPress APIs e.g. function custom_rewrite( $wp_rewrite ) { $feed_rules = array( ‘archives/(\d+)(?:/.*)+’ => ‘index.php?p=’. $wp_rewrite->preg_index(1) ); // ( array merge must be done this way, to ensure new rule comes first ) $wp_rewrite->rules = $feed_rules + $wp_rewrite->rules; } // refresh/flush permalinks in the dashboard if … Read more

Change URL for Blog?

First, you need to change your Front Page settings: 1) Create a Static Page, called “Blog” (and a slug of “blog”) 2) Create another Static Page, to serve as your site Front Page 3) Go to Dashboard -> Settings -> Reading 4) Change “Front Page Displays” from “Your latest posts” to “A static Page (select … Read more