Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Home link block: Add 'current-menu-item' #51478

Merged
merged 8 commits into from
Jul 19, 2023
Merged
17 changes: 15 additions & 2 deletions packages/block-library/src/home-link/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,15 @@ function block_core_home_link_build_li_wrapper_attributes( $context ) {
$colors['css_classes'],
$font_sizes['css_classes']
);
$classes[] = 'wp-block-navigation-item';
$style_attribute = ( $colors['inline_styles'] . $font_sizes['inline_styles'] );
$classes[] = 'wp-block-navigation-item';

if ( is_front_page() ) {
$classes[] = 'current-menu-item';
} elseif ( is_home() && ( (int) get_option( 'page_for_posts' ) !== get_queried_object_id() ) ) {
// Edge case where the Reading settings has a posts page set but not a static homepage.
$classes[] = 'current-menu-item';
}

$wrapper_attributes = get_block_wrapper_attributes(
array(
Expand All @@ -124,8 +131,14 @@ function render_block_core_home_link( $attributes, $content, $block ) {
if ( empty( $attributes['label'] ) ) {
return '';
}
$aria_current = '';

$aria_current = is_home() || ( is_front_page() && 'page' === get_option( 'show_on_front' ) ) ? ' aria-current="page"' : '';
if ( is_front_page() ) {
$aria_current = ' aria-current="page"';
} elseif ( is_home() && ( (int) get_option( 'page_for_posts' ) !== get_queried_object_id() ) ) {
// Edge case where the Reading settings has a posts page set but not a static homepage.
$aria_current = ' 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>',
Expand Down