Skip to content

Commit

Permalink
Site Breadcrumbs: Return empty string when breadcrumbs is an empty array
Browse files Browse the repository at this point in the history
In the design of most wporg sites, breadcrumbs are not needed when the level is less than 3. Therefore, a filter is usually applied to the breadcrumbs block to make the breadcrumbs an empty array. If this early return is not implemented, it would still return a div that occupies space.

See WordPress/Learn@6fa130a
  • Loading branch information
renintw committed Jul 7, 2024
1 parent 8509a01 commit 0cb5159
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions mu-plugins/blocks/site-breadcrumbs/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ function render_block( $attributes, $content, $block ) {
*/
$breadcrumbs = apply_filters( 'wporg_block_site_breadcrumbs', $breadcrumbs, $attributes, $block );

if ( empty( $breadcrumbs ) ) {
return '';
}

$content = '';
foreach ( $breadcrumbs as $i => $crumb ) {
// We can assume that the item without a URL is the current page.
Expand Down

0 comments on commit 0cb5159

Please sign in to comment.