[ Index ]

PHP Cross Reference of WordPress Trunk (Updated Daily)

Search

title

Body

[close]

/wp-includes/blocks/ -> tag-cloud.php (source)

   1  <?php
   2  /**
   3   * Server-side rendering of the `core/tag-cloud` block.
   4   *
   5   * @package WordPress
   6   */
   7  
   8  /**
   9   * Renders the `core/tag-cloud` block on server.
  10   *
  11   * @since 5.2.0
  12   *
  13   * @param array $attributes The block attributes.
  14   *
  15   * @return string Returns the tag cloud for selected taxonomy.
  16   */
  17  function render_block_core_tag_cloud( $attributes ) {
  18      $smallest_font_size_attr = $attributes['smallestFontSize'] ?? null;
  19      $smallest_font_size      = is_string( $smallest_font_size_attr ) ? $smallest_font_size_attr : '';
  20      $unit                    = preg_match( '/^[0-9.]+(?P<unit>[a-z%]+)$/i', $smallest_font_size, $m ) ? $m['unit'] : 'pt';
  21  
  22      $args      = array(
  23          'echo'       => false,
  24          'unit'       => $unit,
  25          'taxonomy'   => $attributes['taxonomy'],
  26          'show_count' => $attributes['showTagCounts'],
  27          'number'     => $attributes['numberOfTags'],
  28          'smallest'   => floatVal( $attributes['smallestFontSize'] ),
  29          'largest'    => floatVal( $attributes['largestFontSize'] ),
  30      );
  31      $tag_cloud = wp_tag_cloud( $args );
  32  
  33      if ( empty( $tag_cloud ) ) {
  34          // Display placeholder content when there are no tags only in editor.
  35          if ( wp_is_serving_rest_request() ) {
  36              $tag_cloud = __( 'There&#8217;s no content to show here yet.' );
  37          } else {
  38              return '';
  39          }
  40      }
  41  
  42      $wrapper_attributes = get_block_wrapper_attributes();
  43  
  44      return sprintf(
  45          '<p %1$s>%2$s</p>',
  46          $wrapper_attributes,
  47          $tag_cloud
  48      );
  49  }
  50  
  51  /**
  52   * Registers the `core/tag-cloud` block on server.
  53   *
  54   * @since 5.2.0
  55   */
  56  function register_block_core_tag_cloud() {
  57      register_block_type_from_metadata(
  58          __DIR__ . '/tag-cloud',
  59          array(
  60              'render_callback' => 'render_block_core_tag_cloud',
  61          )
  62      );
  63  }
  64  add_action( 'init', 'register_block_core_tag_cloud' );


Generated : Sun Sep 13 08:20:28 2026 Cross-referenced by PHPXref