- 赤色のリンクは、まだ日本語Codexに存在しないページ・画像です。英語版と併せてご覧ください。(詳細)
「関数リファレンス/has shortcode」の版間の差分
提供: WordPress Codex 日本語版
< 関数リファレンス
(英文をコピペ。divタグと原文リンクつき) |
(和訳完了。) |
||
2行目: | 2行目: | ||
== 説明 == | == 説明 == | ||
</div> | </div> | ||
− | + | コンテントが特定のショートコードを渡すか否かをチェックする関数です。 | |
<div id="Parameters"> | <div id="Parameters"> | ||
== パラメータ == | == パラメータ == | ||
</div> | </div> | ||
− | {{Parameter|$content| | + | {{Parameter|$content|文字列|検索するコンテント}} |
− | {{Parameter|$tag| | + | {{Parameter|$tag|文字列|検索されるショートコード}} |
<div id="Return"> | <div id="Return"> | ||
== 戻り値 == | == 戻り値 == | ||
</div> | </div> | ||
− | {{Return||Bool| | + | {{Return||Bool|ショートコードがある時 <tt>true</tt>。ない時 <tt>false</tt>。}} |
<div id="Usage"> | <div id="Usage"> | ||
27行目: | 27行目: | ||
$content = 'This is some text, perhaps pulled via $post->post_content. It has a [gallery] short code.'; | $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' ) ) { | if( has_shortcode( $content, 'gallery' ) ) { | ||
− | // | + | // コンテントが [gallery] のショートコードを持つため、 true が返される。 |
} | } | ||
52行目: | 53行目: | ||
{{Shortcode Tags}} | {{Shortcode Tags}} | ||
− | {{原文|Function Reference/has_shortcode| | + | {{原文|Function Reference/has_shortcode|134008}<!-- 13:13, 3 August 2013 Djkaz 版 --> |
{{Tag Footer}} | {{Tag Footer}} |
2013年8月3日 (土) 22:19時点における版
コンテントが特定のショートコードを渡すか否かをチェックする関数です。
パラメータ
- $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}
関数リファレンス、テンプレートタグ目次もご覧ください。