- 赤色のリンクは、まだ日本語Codexに存在しないページ・画像です。英語版と併せてご覧ください。(詳細)
関数リファレンス/has shortcode
提供: WordPress Codex 日本語版
コンテントが特定のショートコードを渡すか否かをチェックする関数です。
パラメータ
- $content
- (文字列) (必須) 検索するコンテント
- 初期値: なし
- $tag
- (文字列) (必須) 検索されるショートコード
- 初期値: なし
戻り値
- (Bool)
- ショートコードがある時 true。ない時 false。
使い方
<?php if ( has_shortcode( $content, 'gallery' ) ) { } ?>
用例
<?php $content = 'This is some text, perhaps pulled via $post->post_content. It has a [gallery] short code.'; // ↑ここのテキストは、 $post->post_content で代入されたものとします。そこには [gallery] ショートコードを持つとします。 if( has_shortcode( $content, 'gallery' ) ) { // コンテントが [gallery] のショートコードを持つため、 true が返される。 } ?>
変更履歴
3.6.0にて導入されました。
ソースファイル
has_shortcode() は wp-includes/shortcodes.php
にあります。
関連資料
ショートコード:
do_shortcode(),
add_shortcode(),
remove_shortcode(),
remove_all_shortcodes(),
shortcode_atts(),
strip_shortcodes(),
shortcode_exists(),
has_shortcode(),
get_shortcode_regex(),
wp_audio_shortcode(),
wp_video_shortcode(),
フィルター no_texturize_shortcodes /en
{{原文|Function Reference/has_shortcode|134008}
関数リファレンス、テンプレートタグ目次もご覧ください。