Generate a localized URL

pom_translate_get_localized_url( string $url, ?string $locale = null ): string resolves an internal URL back to its base route and rebuilds it for the target locale.

$url = pom_translate_get_localized_url( get_permalink( 42 ), 'es_ES' );

It supports absolute and root-relative internal URLs, preserves query strings, fragments, and trailing-slash form, and returns external URLs unchanged. An unavailable locale falls back to the base locale.

The helper can apply stored post and term slugs as part of normal route resolution. For a standalone registered custom destination, use pom_translate_get_translated_custom_url().

Do not concatenate locale prefixes or localized slugs manually. That can double-prefix an existing localized URL and cannot correctly rebuild hierarchical routes.

Apply esc_url() when rendering the result into HTML. Verify the final route while logged out and include pagination or endpoint values when your integration creates them.