That’s strange. Are you sure there’s no space (or non-breaking space) or new line in the editor?
Thanks for your thoughts.
It is indeed strange.
The text editor shows nothing ie. no spaces or returns so I looked in the postmeta table for the page in question and there is a meta key as follows:
_mcb-cta-1
but the meta value is empty.
I checked for new lines or spaces and there aren’t any.
Can you suggest anything I can do to pin point the issue?
OK I have a clue.
I think I had some content in these block initially which I deleted hoping that it would return to the default content.
When I inspect the code in the browser for the block it shows only an empty paragraph.
This isn’t in the postmeta field so is it possible that wordpress itself is adding the <p> tags which is causing the has_block() to return TRUE and resulting in the output being blank since it is an empty <p>.
In fact checking all the other pages that should have default content in these blocks, they all contain empty <p> tags which is why they are blank.
Could it be that in this function
get_the_block()
used in the has_block() function, the defaults being set to:
'apply_filters' => true
enable the apply_filters switch which might be causing the issue.
As a test I set
apply_filters => false
and the default content shows again. 🙂
So I guess I need to figure out how to set apply_filters=>false when I call the has_content() but it’s to late now.
So might this be correct:
has_block( $name, array(
'label' =>'',
'type' => '',
'apply_filters' => false,
) );
`
I tested this theory today and it works perfectly so can I suggest that this might be a bug and that the has_block() function should default to ‘apply_filters’ => false.
Thanks for your research on this. I’ve created an issue on the Github page, we’ll look into this as soon as we have some time to do so.
https://github.com/trendwerk/multiple-content-blocks/issues/65
I have tried several things on the latest WordPress, but could not reproduce this bug. Upon removing all content from a block, WordPress doesn’t add the paragraphs.
What WordPress version were you using? Could you give me some steps on how to reproduce this on a clean install?
Cannot reproduce, so marking this as resolved for now. Let me know if you have any more information.