19 } |
19 } |
20 |
20 |
21 $tag_name = 'h1'; |
21 $tag_name = 'h1'; |
22 $align_class_name = empty( $attributes['textAlign'] ) ? '' : "has-text-align-{$attributes['textAlign']}"; |
22 $align_class_name = empty( $attributes['textAlign'] ) ? '' : "has-text-align-{$attributes['textAlign']}"; |
23 |
23 |
|
24 $aria_current = is_home() || ( is_front_page() && 'page' === get_option( 'show_on_front' ) ) ? ' aria-current="page"' : ''; |
|
25 |
24 if ( isset( $attributes['level'] ) ) { |
26 if ( isset( $attributes['level'] ) ) { |
25 $tag_name = 0 === $attributes['level'] ? 'p' : 'h' . $attributes['level']; |
27 $tag_name = 0 === $attributes['level'] ? 'p' : 'h' . (int) $attributes['level']; |
26 } |
28 } |
27 |
29 |
28 $link = sprintf( '<a href="%1$s" rel="home">%2$s</a>', get_bloginfo( 'url' ), $site_title ); |
30 if ( $attributes['isLink'] ) { |
|
31 $link_attrs = array( |
|
32 'href="' . esc_url( get_bloginfo( 'url' ) ) . '"', |
|
33 'rel="' . esc_attr( 'home' ) . '"', |
|
34 $aria_current, |
|
35 ); |
|
36 if ( '_blank' === $attributes['linkTarget'] ) { |
|
37 $link_attrs[] = 'target="_blank"'; |
|
38 } |
|
39 $site_title = sprintf( '<a %1$s>%2$s</a>', implode( ' ', $link_attrs ), esc_html( $site_title ) ); |
|
40 } |
29 $wrapper_attributes = get_block_wrapper_attributes( array( 'class' => $align_class_name ) ); |
41 $wrapper_attributes = get_block_wrapper_attributes( array( 'class' => $align_class_name ) ); |
30 |
42 |
31 return sprintf( |
43 return sprintf( |
32 '<%1$s %2$s>%3$s</%1$s>', |
44 '<%1$s %2$s>%3$s</%1$s>', |
33 $tag_name, |
45 $tag_name, |
34 $wrapper_attributes, |
46 $wrapper_attributes, |
35 $link |
47 // already pre-escaped if it is a link. |
|
48 $attributes['isLink'] ? $site_title : esc_html( $site_title ) |
36 ); |
49 ); |
37 } |
50 } |
38 |
51 |
39 /** |
52 /** |
40 * Registers the `core/site-title` block on the server. |
53 * Registers the `core/site-title` block on the server. |