render_block_core_social_link

函式
render_block_core_social_link ( $attributes )
引數
  • (array) $attributes The block attributes.
    Required:
返回值
  • (string) Rendered HTML of the referenced block.
定義位置
相關方法
register_block_core_social_linkrender_block_core_home_linkrender_block_core_site_taglinerender_block_core_blockrender_block_core_calendar
引入
-
棄用
-

render_block_core_social_link: 這是一個WordPress的核心函式,用於在編輯器中渲染社交連結塊。它被用來在網站的前端輸出該塊的HTML標記。

渲染伺服器上的`core/social-link`區塊。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
function render_block_core_social_link( $attributes ) {
$service = ( isset( $attributes['service'] ) ) ? $attributes['service'] : 'Icon';
$url = ( isset( $attributes['url'] ) ) ? $attributes['url'] : false;
$label = ( isset( $attributes['label'] ) ) ?
$attributes['label'] :
/* translators: %s: Social Link service name */
sprintf( __( 'Link to %s' ), block_core_social_link_get_name( $service ) );
// Don't render a link if there is no URL set.
if ( ! $url ) {
return '';
}
$icon = block_core_social_link_get_icon( $service );
return '<li class="wp-social-link wp-social-link-' . esc_attr( $service ) . '"><a href="' . esc_url( $url ) . '" aria-label="' . esc_attr( $label ) . '"> ' . $icon . '</a></li>';
}
function render_block_core_social_link( $attributes ) { $service = ( isset( $attributes['service'] ) ) ? $attributes['service'] : 'Icon'; $url = ( isset( $attributes['url'] ) ) ? $attributes['url'] : false; $label = ( isset( $attributes['label'] ) ) ? $attributes['label'] : /* translators: %s: Social Link service name */ sprintf( __( 'Link to %s' ), block_core_social_link_get_name( $service ) ); // Don't render a link if there is no URL set. if ( ! $url ) { return ''; } $icon = block_core_social_link_get_icon( $service ); return '<li class="wp-social-link wp-social-link-' . esc_attr( $service ) . '"><a href="' . esc_url( $url ) . '" aria-label="' . esc_attr( $label ) . '"> ' . $icon . '</a></li>'; }
function render_block_core_social_link( $attributes ) {
	$service = ( isset( $attributes['service'] ) ) ? $attributes['service'] : 'Icon';
	$url     = ( isset( $attributes['url'] ) ) ? $attributes['url'] : false;
	$label   = ( isset( $attributes['label'] ) ) ?
		$attributes['label'] :
		/* translators: %s: Social Link service name */
		sprintf( __( 'Link to %s' ), block_core_social_link_get_name( $service ) );

	// Don't render a link if there is no URL set.
	if ( ! $url ) {
		return '';
	}

	$icon = block_core_social_link_get_icon( $service );
	return '<li class="wp-social-link wp-social-link-' . esc_attr( $service ) . '"><a href="' . esc_url( $url ) . '" aria-label="' . esc_attr( $label ) . '"> ' . $icon . '</a></li>';
}

常見問題

FAQs
檢視更多 >