site-title.php (1234B)
1 <?php 2 /** 3 * Server-side rendering of the `core/site-title` block. 4 * 5 * @package WordPress 6 */ 7 8 /** 9 * Renders the `core/site-title` block on the server. 10 * 11 * @param array $attributes The block attributes. 12 * 13 * @return string The render. 14 */ 15 function render_block_core_site_title( $attributes ) { 16 $site_title = get_bloginfo( 'name' ); 17 if ( ! $site_title ) { 18 return; 19 } 20 21 $tag_name = 'h1'; 22 $align_class_name = empty( $attributes['textAlign'] ) ? '' : "has-text-align-{$attributes['textAlign']}"; 23 24 if ( isset( $attributes['level'] ) ) { 25 $tag_name = 0 === $attributes['level'] ? 'p' : 'h' . $attributes['level']; 26 } 27 28 $link = sprintf( '<a href="%1$s" rel="home">%2$s</a>', get_bloginfo( 'url' ), $site_title ); 29 $wrapper_attributes = get_block_wrapper_attributes( array( 'class' => $align_class_name ) ); 30 31 return sprintf( 32 '<%1$s %2$s>%3$s</%1$s>', 33 $tag_name, 34 $wrapper_attributes, 35 $link 36 ); 37 } 38 39 /** 40 * Registers the `core/site-title` block on the server. 41 */ 42 function register_block_core_site_title() { 43 register_block_type_from_metadata( 44 __DIR__ . '/site-title', 45 array( 46 'render_callback' => 'render_block_core_site_title', 47 ) 48 ); 49 } 50 add_action( 'init', 'register_block_core_site_title' );