render_block_core_home_link

函式
render_block_core_home_link ( $attributes, $content, $block )
引數
  • (array) $attributes The block attributes.
    Required:
  • (string) $content The saved content.
    Required:
  • (WP_Block) $block The parsed block.
    Required:
返回值
  • (string) Returns the post content with the home url added.
定義位置
相關方法
register_block_core_home_linkrender_block_core_social_linkrender_block_core_comment_edit_linkrender_block_core_comment_reply_linkrender_block_core_comments
引入
-
棄用
-

render_block_core_home_link: 這個函式用來渲染WordPress中的主頁連結塊。主頁連結塊允許使用者新增一個連結到他們網站的主頁: 這個函式負責生成主頁連結塊的HTML標記。

渲染`core/home-link`區塊。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
function render_block_core_home_link( $attributes, $content, $block ) {
if ( empty( $attributes['label'] ) ) {
return '';
}
$aria_current = is_home() || ( is_front_page() && 'page' === get_option( 'show_on_front' ) ) ? ' aria-current="page"' : '';
return sprintf(
'<li %1$s><a class="wp-block-home-link__content wp-block-navigation-item__content" href="%2$s" "rel="home"%3$s>%4$s</a></li>',
block_core_home_link_build_li_wrapper_attributes( $block->context ),
esc_url( home_url() ),
$aria_current,
wp_kses_post( $attributes['label'] )
);
}
function render_block_core_home_link( $attributes, $content, $block ) { if ( empty( $attributes['label'] ) ) { return ''; } $aria_current = is_home() || ( is_front_page() && 'page' === get_option( 'show_on_front' ) ) ? ' aria-current="page"' : ''; return sprintf( '<li %1$s><a class="wp-block-home-link__content wp-block-navigation-item__content" href="%2$s" "rel="home"%3$s>%4$s</a></li>', block_core_home_link_build_li_wrapper_attributes( $block->context ), esc_url( home_url() ), $aria_current, wp_kses_post( $attributes['label'] ) ); }
function render_block_core_home_link( $attributes, $content, $block ) {
	if ( empty( $attributes['label'] ) ) {
		return '';
	}

	$aria_current = is_home() || ( is_front_page() && 'page' === get_option( 'show_on_front' ) ) ? ' aria-current="page"' : '';

	return sprintf(
		'<li %1$s><a class="wp-block-home-link__content wp-block-navigation-item__content" href="%2$s" "rel="home"%3$s>%4$s</a></li>',
		block_core_home_link_build_li_wrapper_attributes( $block->context ),
		esc_url( home_url() ),
		$aria_current,
		wp_kses_post( $attributes['label'] )
	);
}

常見問題

FAQs
檢視更多 >