Brak opisu

site-title.php 1.2KB

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