How to 301 redirect from url with post id to permalink with post name (slug)?

yes, it is possible. add a template_redirect hook handler: add_filter(‘template_redirect’, ‘redirect_post_to_canonical_url’); function redirect_post_to_canonical_url(): void { if (!is_single()) { // do not redirect nothing else except posts return; } $canonicalLocation = get_permalink(); $requestUri = $_SERVER[‘REQUEST_URI’]; $currentLocation = home_url(“https://wordpress.stackexchange.com/”) . substr($requestUri, 1); if ($currentLocation === $canonicalLocation) { // prevent from infinite redirect loop return; } wp_redirect($canonicalLocation, 301); … Read more

Internal forward link with add_rewrite_rule

The code below should work for you as long as: Your CPT slug is location. You don’t have a custom query_var registered for your CPT location. You probably don’t have. Refer to https://codex.wordpress.org/Function_Reference/register_post_type#query_var for more information, it’s very usefull, btw. And I’m assuming the string nyc is the slug of your single custom post. function … Read more

Permalink conflict with React Router in subfolder

I managed to get it working by placing the following in an .htaccess file in my React app folder: <IfModule mod_rewrite.c> RewriteEngine on # Don’t rewrite files or directories RewriteCond %{REQUEST_FILENAME} -f [OR] RewriteCond %{REQUEST_FILENAME} -d RewriteRule ^ – [L] # Rewrite everything else to index.html to allow html5 state links RewriteRule ^ index.html [L] … Read more

WP adding noopener and noreferrer to all links

So WordPress provides a way to adjust these programmatically, but it’s done at the time of post save, not post render, so the changes will only apply once you add the code snippet to your site, and the go and re-save your post(s). And, it’s only available from WP 5.1+ Here’s the code snippet (add … Read more