apply_filters( 'wpml_element_link', int $element_id, string $element_type, string $link_text, array $optional_parameters, string $anchor, bool $echo, bool $return_original_if_missing )
- タイプ
- filter
- カテゴリー
- ローカライズされたコンテンツの取得
- WPMLバージョン
- 3.2
説明
現在の言語で投稿タイプのリンク、またはタクソノミータームのリンクを返します。
* 注: 開発者がHTML出力をより詳細に制御できる、要素のリンクを取得する別の方法もあります。
WordPressには、これを実行するためのget_permalink()やget_term_link()などの関数が多数用意されています。
パラメーターとして投稿タイプまたはタームIDを必要とする関数を使用する予定がある場合は、wpml_object_idフィルターを調べることをお勧めします。
引数
- $element_id
- (int)(必須) リンク先の投稿タイプ(post、page、attachment、カスタム投稿)またはタクソノミーターム(tag、category、カスタムタクソノミー)のID
- $element_type
- (string)(オプション) リンク先の要素のタイプ。'post’、'page’、'attachment’、'{custom post}'、'tag’、'category’、'{custom taxonomy}'を指定できます。デフォルトは’post’です
- $link_text
- (string)(オプション) リンクテキスト。デフォルトは要素の名前です
- $optional_parameters
- (array)(オプション) リンクの引数
- $anchor
- (string)(オプション) リンクのアンカー
- $echo
- (bool)(オプション) ローカライズされたリンクを返す場合は0|false、echoする場合は1|true。デフォルトはtrueです
- $return_original_if_missing
- (bool)(オプション) trueに設定すると、常に値を返します(翻訳がない場合は元の値を返します)。デフォルトはTRUEです
使用例
例
//produces: <a href="/hello-world/">Hello World!</a> apply_filters( 'wpml_element_link', 1 ); //produces: <a href="/sample-page/">Custom link text for the sample page</a> apply_filters( 'wpml_element_link', 2, 'page', __( 'Custom link text for the sample page' ) ); //produces: <a href="/sample-page/?category=foo&bar=baz">Sample Page</a> apply_filters( 'wpml_element_link', 2, 'page', '', array( 'category'=>'foo', 'bar'=>'baz' ) ); //produces: <a href="/sample-page/#contact">Sample Page</a> apply_filters( 'wpml_element_link', 2, 'page', '', '', 'contact' ); //produces: <a href="/category/uncategorized/">Uncategorized</a> apply_filters( 'wpml_element_link', 1, 'category' ); //produces: <a href="/ja/?attachment_id=25">'Attachment image title</a> apply_filters( 'wpml_element_link', 25, 'attachment', __( 'Attachment image title' ) );
関連するフック
wpml_media_url, wpml_media_id, force_suppress_filters, wpml_get_translated_slug, wpml_home_url, wpml_translate_single_string, wpml_translate_string, wpml_elements_without_translations, wpml_permalink, wpml_unfiltered_admin_string