I have several ACF blocks that I use as widgets in my site’s sidebar. Several of these are simply WP_Query’s that list recent posts of a given content type. For example, artwork I have created in the last three months or posts from exactly one year ago today.
Often these blocks will be empty, but WordPress still renders the containing <section>
block as an empty tag:
<section id="block-12" class="widget widget_block"></section>
Is there a way to prevent WordPress from rendering this empty tag if the block is empty?
For example, in my-acf-block.php, is there something I could put in the else
statement of if ($posts->have_posts()) :
that would tell the WordPress there’s nothing here to render?