[ Index ]

PHP Cross Reference of WordPress Trunk (Updated Daily)

Search

title

Body

[close]

/wp-includes/blocks/ -> site-title.php (source)

   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      $classes  = empty( $attributes['textAlign'] ) ? '' : "has-text-align-{$attributes['textAlign']}";
  23      if ( isset( $attributes['style']['elements']['link']['color']['text'] ) ) {
  24          $classes .= ' has-link-color';
  25      }
  26  
  27      if ( isset( $attributes['level'] ) ) {
  28          $tag_name = 0 === $attributes['level'] ? 'p' : 'h' . (int) $attributes['level'];
  29      }
  30  
  31      if ( $attributes['isLink'] ) {
  32          $aria_current = is_home() || ( is_front_page() && 'page' === get_option( 'show_on_front' ) ) ? ' aria-current="page"' : '';
  33          $link_target  = ! empty( $attributes['linkTarget'] ) ? $attributes['linkTarget'] : '_self';
  34  
  35          $site_title = sprintf(
  36              '<a href="%1$s" target="%2$s" rel="home"%3$s>%4$s</a>',
  37              esc_url( home_url() ),
  38              esc_attr( $link_target ),
  39              $aria_current,
  40              esc_html( $site_title )
  41          );
  42      }
  43      $wrapper_attributes = get_block_wrapper_attributes( array( 'class' => trim( $classes ) ) );
  44  
  45      return sprintf(
  46          '<%1$s %2$s>%3$s</%1$s>',
  47          $tag_name,
  48          $wrapper_attributes,
  49          // already pre-escaped if it is a link.
  50          $attributes['isLink'] ? $site_title : esc_html( $site_title )
  51      );
  52  }
  53  
  54  /**
  55   * Registers the `core/site-title` block on the server.
  56   */
  57  function register_block_core_site_title() {
  58      register_block_type_from_metadata(
  59          __DIR__ . '/site-title',
  60          array(
  61              'render_callback' => 'render_block_core_site_title',
  62          )
  63      );
  64  }
  65  add_action( 'init', 'register_block_core_site_title' );


Generated : Thu Apr 25 08:20:02 2024 Cross-referenced by PHPXref