Skip to content

Commit

Permalink
Home link block: Add 'current-menu-item' (#51478)
Browse files Browse the repository at this point in the history
* Home link block: Add 'current-menu-item'

* Update index.php

* CS

* Update index.php

* Remove variables that were only used once
  • Loading branch information
carolinan authored Jul 19, 2023
1 parent b497051 commit d27c43f
Showing 1 changed file with 15 additions and 2 deletions.
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

0 comments on commit d27c43f

Please sign in to comment.