wp_rel_ugc

函式
wp_rel_ugc ( $text )
引數
  • (string) $text Content that may contain HTML A elements.
    Required:
返回值
  • (string) Converted content.
定義位置
相關方法
wp_rel_callbackwp_parse_urlwp_create_tagwp_parse_argswp_list_pluck
引入
5.3.0
棄用
-

wp_rel_ugc: 這個函式用於為一個連結新增rel=”ugc”屬性。它接受幾個引數,包括連結的屬性。

為內容中的所有HTML A元素新增`rel="nofollow ugc"`字串。

function wp_rel_ugc( $text ) {
	// This is a pre-save filter, so text is already escaped.
	$text = stripslashes( $text );
	$text = preg_replace_callback(
		'|<a (.+?)>|i',
		static function( $matches ) {
			return wp_rel_callback( $matches, 'nofollow ugc' );
		},
		$text
	);
	return wp_slash( $text );
}

常見問題

FAQs
檢視更多 >