From cf4d798badcf83d1815b72399cf57dedf226160e Mon Sep 17 00:00:00 2001 From: Sunil Prajapati <61308756+akasunil@users.noreply.github.com> Date: Thu, 22 Aug 2024 19:07:30 +0530 Subject: [PATCH] Tag Cloud: Improve state of block with no tags (#63774) * Render nothing when no tags are available in tag cloud block * Added condition to display placeholder in editor * Fix phpcs errors * Use wp_is_serving_rest_request function for conditional check Co-authored-by: akasunil Co-authored-by: Mamaduka Co-authored-by: richtabor --- packages/block-library/src/tag-cloud/index.php | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/packages/block-library/src/tag-cloud/index.php b/packages/block-library/src/tag-cloud/index.php index 69b8c25ec8720..8949dd8e5b11f 100644 --- a/packages/block-library/src/tag-cloud/index.php +++ b/packages/block-library/src/tag-cloud/index.php @@ -29,8 +29,13 @@ function render_block_core_tag_cloud( $attributes ) { ); $tag_cloud = wp_tag_cloud( $args ); - if ( ! $tag_cloud ) { - $tag_cloud = __( 'There’s no content to show here yet.' ); + if ( empty( $tag_cloud ) ) { + // Display placeholder content when there are no tags only in editor. + if ( wp_is_serving_rest_request() ) { + $tag_cloud = __( 'There’s no content to show here yet.' ); + } else { + return ''; + } } $wrapper_attributes = get_block_wrapper_attributes();