Skip to main content
14 events
when toggle format what by license comment
Jun 15, 2021 at 2:40 comment added Sally CJ That's what my code is doing, except for this: "do not generate url from the default setting at all", and I mentioned Yoast source code because if we could find out what WordPress hook/function they use to generate the redirect URL, then we can do that last part in your previous comment. But you can try replacing the preg_match( '#^zh-han[st]$#', pll_get_post_language( $post->ID ) ) with 'en' !== pll_get_post_language( $post->ID ).
Jun 15, 2021 at 1:46 comment added Atimmy Yes your code works for my purpose, thank you for your help. the yoast redirection things doesn't hurt much. I was just curious that, can't we tell WP not to generate the post url twice. I thought we can tell WP "if lang for the post is not english, use our custom code for setting up the permalink, do not generate url from the default setting at all
Jun 15, 2021 at 1:29 comment added Sally CJ If this is what you meant, then although Yoast SEO may not be at fault, I can't help you any further, unless maybe if I see the Yoast SEO premium's source. And I'm not saying my code is perfect, but it worked for what it's for - setting a custom permalink structure for certain posts only - right? So maybe try asking in Yoast forums and ask if there's any way to disable/filter the redirect URLs via a hook.
Jun 15, 2021 at 0:33 vote accept Atimmy
Jun 14, 2021 at 17:13 comment added Atimmy or maybe a if lang != "en" ..then use the custom function to setup the permalink instead ...
Jun 14, 2021 at 17:12 comment added Atimmy so I think what actually happened was that when I use the custom function code to create different permalink rule for non-english posts, when I click saved, WP use the URL rules FIRST and created the link accordingly, and then right after that, the custom function code update the permalink update, which trigger the yoast seo plugin to create a 301 redirection. if there is a way to hook the function replace the WP permalink setting, it will work perfectly
Jun 14, 2021 at 17:08 comment added Atimmy when yoast detect a URL change of a post, in order to avoid 404 page not found, it will automatically create a redirection link. For example, if I create a post with url "example.com/blog/hello-world" and then I update its permalink to "example.com/blog/hello-hello", then yoast will automatically create a "blog/hello-world" ---> "blog/hello-hello" redirection
Jun 14, 2021 at 14:09 comment added Sally CJ If you mean the original permalink with the slug in the URL (e.g. example.com/zh-hant/blog/uncategorized-zh-hant/你好,世界!), then yes, I didn't include the code which disables that original URL.
Jun 14, 2021 at 14:07 comment added Sally CJ Actually, what do you mean by "create URL redirection"? Can you try disabling all other plugins? Did you use Gutenberg or the old/classic editor? If you deactivate Yoast, does the issue persist? Can you show (like via a short video) the steps you took when "saving" the post?
Jun 14, 2021 at 13:05 comment added Atimmy Tried the update code, the site still create chinese URL first before the custom code. Overall, it still works for me, I just have to delete the redirection from yoast plugin, thank you for your help Sally. PS. I still need help with the other question... kindly help me out when you have time. Thank you again!
Jun 14, 2021 at 10:02 comment added Sally CJ Try the updated code in step 2, but if the issue still happens, then I'm afraid there's nothing else I could do..
Jun 14, 2021 at 10:00 history edited Sally CJ CC BY-SA 4.0
Updated the code in step 2
Jun 14, 2021 at 9:24 comment added Atimmy Hi Sally, thank you for the answer. It works like a charm. Only thing I notice is that I have yoast SEO plugin installed, and when I create a new post in Chinese, upon clicking on the save button, it trigger yoast plugin to create URL redirection. Seems like when I save the post, it created chinese character URL permalink first and immediate the custom function takes effect... and since there was a URL changed, it triggered yoast plugin to created an URL redirection.
Jun 14, 2021 at 7:05 history answered Sally CJ CC BY-SA 4.0