do_shortcode

函式
do_shortcode ( $content, $ignore_html = false )
引數
  • (string) $content Content to search for shortcodes.
    Required:
  • (bool) $ignore_html When true, shortcodes inside HTML elements will be skipped. Default false.
    Required:
    Default: false
返回值
  • (string) Content with shortcodes filtered out.
定義位置
相關方法
add_shortcodedo_shortcode_taghas_shortcodewp_video_shortcodewp_audio_shortcode
引入
2.5.0
棄用
-

do_shortcode: 這是一個WordPress函式,用於處理一個短碼字串並返回結果。短碼是一些小的程式碼,可以在WordPress的文章和頁面中用來新增動態內容,如按鈕或畫廊。

為短程式碼搜尋內容,並通過其鉤子過濾短程式碼。

如果沒有定義短碼標籤,那麼內容將被返回,而不進行任何過濾: 當外掛被禁用時,這可能會導致問題,但短碼仍將顯示在文章或內容中。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
function do_shortcode( $content, $ignore_html = false ) {
global $shortcode_tags;
if ( false === strpos( $content, '[' ) ) {
return $content;
}
if ( empty( $shortcode_tags ) || ! is_array( $shortcode_tags ) ) {
return $content;
}
// Find all registered tag names in $content.
preg_match_all( '@[([^<>&/[]x00-x20=]++)@', $content, $matches );
$tagnames = array_intersect( array_keys( $shortcode_tags ), $matches[1] );
if ( empty( $tagnames ) ) {
return $content;
}
$content = do_shortcodes_in_html_tags( $content, $ignore_html, $tagnames );
$pattern = get_shortcode_regex( $tagnames );
$content = preg_replace_callback( "/$pattern/", 'do_shortcode_tag', $content );
// Always restore square braces so we don't break things like <!--[if IE ]>.
$content = unescape_invalid_shortcodes( $content );
return $content;
}
function do_shortcode( $content, $ignore_html = false ) { global $shortcode_tags; if ( false === strpos( $content, '[' ) ) { return $content; } if ( empty( $shortcode_tags ) || ! is_array( $shortcode_tags ) ) { return $content; } // Find all registered tag names in $content. preg_match_all( '@[([^<>&/[]x00-x20=]++)@', $content, $matches ); $tagnames = array_intersect( array_keys( $shortcode_tags ), $matches[1] ); if ( empty( $tagnames ) ) { return $content; } $content = do_shortcodes_in_html_tags( $content, $ignore_html, $tagnames ); $pattern = get_shortcode_regex( $tagnames ); $content = preg_replace_callback( "/$pattern/", 'do_shortcode_tag', $content ); // Always restore square braces so we don't break things like <!--[if IE ]>. $content = unescape_invalid_shortcodes( $content ); return $content; }
function do_shortcode( $content, $ignore_html = false ) {
	global $shortcode_tags;

	if ( false === strpos( $content, '[' ) ) {
		return $content;
	}

	if ( empty( $shortcode_tags ) || ! is_array( $shortcode_tags ) ) {
		return $content;
	}

	// Find all registered tag names in $content.
	preg_match_all( '@[([^<>&/[]x00-x20=]++)@', $content, $matches );
	$tagnames = array_intersect( array_keys( $shortcode_tags ), $matches[1] );

	if ( empty( $tagnames ) ) {
		return $content;
	}

	$content = do_shortcodes_in_html_tags( $content, $ignore_html, $tagnames );

	$pattern = get_shortcode_regex( $tagnames );
	$content = preg_replace_callback( "/$pattern/", 'do_shortcode_tag', $content );

	// Always restore square braces so we don't break things like <!--[if IE ]>.
	$content = unescape_invalid_shortcodes( $content );

	return $content;
}

常見問題

FAQs
檢視更多 >