シグネチャPHP
$converted_url = apply_filters( 'wpml_site_url_in_language', string $url, string $language_code, string $source_language_code = null );
説明
wpml_permalinkフィルターが完全な解決で行うのと同様に、このサイトのURLを別の言語の同じアドレスに変換します。ユーザーがフォームやカスタムフィールドに入力したリンクなど、自分で構築していないURLに使用します。
フィルターは、URLがこのサイトのページアドレスである場合にのみURLを変換します。
- URLが
http://またはhttps://で始まります。 - ホストがサイトのホストか、「言語ごとに異なるドメイン」が選択されている場合は言語のドメインです。
- パスがサイトのホームURLのパス内にあります。
.pdfや.jpgのようなファイルを指していません。wp-content、wp-includes、またはwp-admin内にありません。wpml_should_resolve_single_urlフィルターがそれに対してfalseを返しません。
投稿、ページ、またはタームのURLは、その翻訳のURLになります。ホームURLや日付アーカイブなど、背後に投稿やタームがないURLには、サイトの言語URL形式が適用されます。フィルターはクエリ文字列とフラグメントを保持します。
フィルターは、外部URL、相対URL、mailto:およびtel:リンク、#topのようなアンカー、文字列ではない値など、その他のすべての値をそのまま返します。
引数
$urlstring必須変換するURL。例:ユーザーがフィールドに入力したURL。$language_codestring必須URLの変換先の言語。例:fr。$source_language_codestring任意URLが含まれるコンテンツの言語。WPMLはこれをwpml_should_resolve_single_urlフィルターに渡します。デフォルトはnullです。
使用例
例
「ディレクトリごとの異なる言語」が選択されている場合:
PHP
// returns http://example.org/fr/contact/ (the translation of the page) $url = apply_filters( 'wpml_site_url_in_language', 'http://example.org/contact/', 'fr' ); // returns http://example.org/fr/2026/05/ (a date archive, with no post behind it) $url = apply_filters( 'wpml_site_url_in_language', 'http://example.org/2026/05/', 'fr' ); // returns the URL as it is (a file) $url = apply_filters( 'wpml_site_url_in_language', 'http://example.org/wp-content/uploads/menu.pdf', 'fr' ); // returns the URL as it is (another site) $url = apply_filters( 'wpml_site_url_in_language', 'https://wordpress.org/', 'fr' );