Change the generated URLs
-
I am successfully using your snippet to resolve localization of my cpt. If I wanted to extend this for my custom taxonomy slugs do I need to create an entirely new function specific for the taxonomy or can I add some code to this one?
Thanks.
-
You can just add the necessary code to one function.
Read on here: http://codex.ww.wp.xz.cn/Conditional_Tags#A_Post_Type
Cheers,
Dennis.Thanks Dennis,
This is working very well for my cpt slugs. For my custom tax, it works once in one direction and then stops switching. In other words:When I use the switcher like this I have succes:
eng-custom-tax/eng-post-slug -> fr-custom-tax/fr-post-slugBut when I use it to go back, this is what I get:
fr-custom-tax/fr-post-slug -> fr-custom-tax/eng-post-slugAny ideas what might be messing up the round trip?
Just for information: I have my .po and .mo files all good. My custom tax is registered like so:
'rewrite' => array( 'slug' => _x('workshop/category', 'URL slug', 'ismh-workshops'), 'with_front' => true, 'query_var' => true ),And in my functions.php I have:
function my_url_translator( $url, $language ) { if ( 'fr_FR' == $language ) { $url = str_replace( '/workshop/category/', '/atelier/categorie/', $url ); } return $url; } add_filter( 'msls_options_get_permalink', 'my_url_translator', 10, 2 );Thanks
It would be interesting to know what’s in $url in the problematic case.
Is this problem resolved?
Hi, thank-you for follow-up; I have been away on holiday and back to this project today.
No, the issue is not resolved however I am unsure how to answer your question.
I will try to reiterate the problem here:
Starting from english:
domain.dev/workshop/category/youth/
I click the language switcher which takes me to french:
fr.domain.dev/atelier/categorie/jeunes/
Which is the desired outcome.From there if I click on the switcher again to go back to english custom category, rather than being take back to the expected domain.dev/workshop/category/youth/, it takes me to domain.dev/atelier/categorie/youth, and obviously a 404 page.
So while the actual category changes back correctly (“jeunes” goes back to “youth”), the rest of the URL does not goes back from “atelier/category” to “worskhop/category”. From English -> French is no problem, but the other direction does not work.
For the sake of clarification, this is not specific to only “youth”, but all custom categories.
Thank-you for any pointers on where I am going wrong.
I think I may have an idea looking at my code above in my
my_url_translatorfunction, which specifies the url replacement from english to french, but perhaps I need also specify from french back to english. I am learning php as I go and I am unsure of this is a case of “multiple if statements” or “else if” but either way I am getting errors. Here is what I am attempting and obviously getting errors:function my_url_translator( $url, $language ) { if ( 'fr_FR' == $language ) { $url = str_replace( '/workshop/category/', '/atelier/categorie/', $url ); } return $url; } if ('fr_FR' !== $language) { $url = str_replace( '/atelier/categorie/', '/workshop/category/', $url ); } return $url; } add_filter( 'msls_options_get_permalink', 'my_url_translator', 10, 2 );Thanks
Hi,
the presence of the first
returnis problematic… Try this:function my_url_translator( $url, $language ) { if ( 'fr_FR' == $language ) { $url = str_replace( '/workshop/category/', '/atelier/categorie/', $url ); } else { $url = str_replace( '/atelier/categorie/', '/workshop/category/', $url ); } return $url; } add_filter( 'msls_options_get_permalink', 'my_url_translator', 10, 2 );Yes!! Thank-you so much for all your generous help customizing the functionality of your fantastic plugin Dennis. Is there a way to donate?
OK, very good. If you don’t want to donate to Greenpeace – which would be great – consider my Amazon Wishlist. π
Thank you so much for your donation to Greenpeace, Lucas!
The topic ‘Change the generated URLs’ is closed to new replies.