-
Hi there, so I have the following issue:
– I have an SVG icon which I have created using the ‘Headline’ GenerateBlock on my website. This icon is part of a ‘query loop’
– I only want this icon to display if the current post within the query loop has an excerpt field filled in.Please can you tell me how this would be possible?
Thanks,
Keith -
David
Hi there,
you could try something like this:
1. add this PHP Snippet to your site:
function remove_block_if_no_excerpt( $block_content, $block ) { if ( !is_admin() && ! empty( $block['attrs']['className'] ) && strpos( $block['attrs']['className'], 'has-excerpt' ) !== false ) { global $post; if ( empty( $post->post_excerpt ) ) { $block_content = ''; } } return $block_content; } add_filter( 'render_block', 'remove_block_if_no_excerpt', 10, 2 );
2. Select the block you want to display IF there is an excerpt, and in block settings Advanced > Additional CSS Classes add:
has-excerpt
Viewing 2 posts - 1 through 2 (of 2 total)
- You must be logged in to reply to this topic.