Auto save permalink setting page with the plugin activation

You should use flush_rewrite_rules function for that. You have to remember, that this is expensive task, so you should not do it every time the site loads (many tutorials are making such mistake). Of course you can use it in your plugin activation hook: register_activation_hook( __FILE__, ‘myplugin_flush_rewrites’ ); function myplugin_flush_rewrites() { // call your rewrite … Read more

Plain permalinks not working!

Plain permalinks of the form /?p=14523 (or /index.php?p=14523) don’t necessarily need any .htaccess file since they don’t require mod_rewrite to rewrite the URL (unlike the the custom permalinks you mention). However, for a URL of the form /?p=14523 (as opposed to /index.php?p=14523), where you don’t explicitly state the index document (ie. index.php) in the URL … Read more

WordPress permalinks that end with a hyphen result in a 404

You could code a database patch in PHP/with the WordPress APIs, but since it sounds like you won’t be repeating this process frequently, I think that’s probably overkill. The most straightforward approach to bulk changes like this is a quick SQL update directly on the database. Bulk Update via SQL Query One large exception to … Read more

Permalink change redirects by WordPress [duplicate]

I think I got it. Made a test site. With permalink structure: year/moth/day/postname. Published a post. Then changed permalinks to postID/post-name. Tested with looking at network stats from the browser. Here’s what I got, a 301 redirect, after trying example.com/2018/11/04/hello-world/ from my browser: I tested another thing. Using different permalink structures, I tried to make … Read more

WordPress custom slug (endpoint) and compare all links

All of the API functions that generate links have filters to let you alter the output. Here’s a quick example that covers most of them: function wpd_endpoint_links( $url ){ if( isset( $_COOKIE[‘lang’] ) ){ $url = $url . $_COOKIE[‘lang’] . “https://wordpress.stackexchange.com/”; } return $url; } add_filter( ‘post_link’, ‘wpd_endpoint_links’ ); add_filter( ‘page_link’, ‘wpd_endpoint_links’ ); add_filter( ‘post_type_link’, … Read more

Rewrite Rule for default post type

When you register your custom post type using register_post_type function, you have to be very careful with rewrite param. You should pass an array with following keys: slug => string Customize the permalink structure slug. Defaults to the $post_type value. Should be translatable. with_front => bool Should the permalink structure be prepended with the front … Read more