Thanks Ladislav for your proposition,
Using icl_object_id
was a good idea, but working on the issue, I realise that I didn't have to bother much about if or not the content had the value 'do nothing' set, because I already knew that, and it won't change. The documentation state that you have to turn off the 'Make themes work multilingual', and it's hard to tell how this will affect the theme, since it's a ThemeForest theme.
I will like to have a truly flexible solution, because that will fixed what I found is an issue with how WPML manage content that doesn't need to be translated.
But, with your suggestion, I continued to look for an answer, and find a beginning of a solution to my issue.
First, to edit the link, I had to set a 'add_filter' that correspond to the type of link I wanted to edit.
add_filter( 'post_type_link', 'add_lang_fr', 10, 2 );
add_filter( 'term_link', 'add_lang_fr', 10, 2 );
And then, I test the url to make sure they match the content that need to have ?lang=fr added.
function add_lang_fr( $url, $post ) {
if ('fr' == ICL_LANGUAGE_CODE) { // if current language is fr
if ( 'article' == get_post_type( $post ) || FALSE !== strpos($url, 'article-tag') ) { // if link goes to a CPT 'article' or have 'article-tag' in url
return add_query_arg('lang', 'fr', $url);
}
}
return ($url);
}
To answer my initial question :
- How can I detect if a content have the value 'do nothing', base on
the url ? - I use a different way to filter the url that need the ?lang=fr added
- How can I add on-the-fly the '?lang=fr' to their url for
these contents ? -
add_query_arg
was the key, since it allows to add query argument on url...which was exactly what I needed.
- It's possible to do this, without slowing down the
site ? - with this solution I have 150 extra request and +16 sec of loading (the page tested have about 2000 url that have been edited).
It's there a way to reduce the number of call and improve the page loading ?