I am a developer rolling a custom theme based on Bootscore, and I am wondering if there's any function to get the link to a certain page in the current language.
Example: I have a page "shipments" in the base language (english) and I have a translated slug as "envios" for spanish language.
In standard WP I'd use home_url("shipments") to get the page url but wp_home_url("shipments") will only yield the home page in the language, not the shipments page as expected ("/envios").
Hi Andreas! Thanks both links are really useful. wpml_element_link() might be the closest to what i'm looking for. I've wrapped in function (see below) to call it by slug which is more preferable. I'd prefer to have a wpml_element_url() function that only brings the url without the to provide styling etc, but this is close enough.
In the end for this case, I'll be using a secondary menu location for the footer menu (this is to show some specific pages there) which translates automatically and I can set the css style as desired.
/**
* Get current language url from original slug
*/
function wpml_lang_url($slug) {
$page = get_page_by_path($slug);
if ($page) {
$id = $page->ID;
return apply_filters( 'wpml_element_link', $id, 'post', '', [], '', false );
}
return null;
}