Get the current post/page URL with plain permalinks
Is there a reason why get_permalink() doesn’t work for you? I’m unclear why you are trying to construct it manually.
Is there a reason why get_permalink() doesn’t work for you? I’m unclear why you are trying to construct it manually.
The code you are using looks valid, so… Before going any further, check to see that the post you are testing with actually has the term you are expecting to find (and replace). In other words, verify your input is valid. Also, you might consider just doing a straight string replace on the URL as, … Read more
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
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
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
Enabling hierarchical in a Custom Post Type gives error 404
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
Redirect page to homepage, keeping URL
WordPress generates weird permalinks
As far as I understand your question, you’re looking to list out taxonomies on one page and you already set URL for post(s). This URL can help with creating custom taxonomy page. Go through it and I’m sure that’s your solution.