Hi,
Can you provide me a code example where you set the block background? You must make it using a unique classname/ID, or add styles inline.
Regards,
Nikita.
Hi! Within block.php I have the following code:
<section class="full-width-container" style="background-color:<?php
echo get_lzb_meta('background-color'); ?>; padding: <?php
echo get_lzb_meta('spacing'); ?>px 0; color: <?php
echo get_lzb_meta('font-color'); ?>;">
<div class="container">
<div class="row">
<InnerBlocks/>
</div>
</div>
</section>
This basically means it is inline code, isn’t it? When having two blocks in the same site, the background color changes for all elements within the site.
Update: The problem seems to exist only for the color picker and only if using the “save in meta” option (not with $attributes). Furthermore it looks like it has nothing to do with the actually saved meta value, within the Gutenberg editor always adjusts it for all blocks (a “frontend” problem).
-
This reply was modified 1 year, 7 months ago by
Blackbam.
Hi,
Meta value is saved to the post data. So, when you add multiple blocks that work with the single meta, the value will be taken from post data, not from the individual block. This is why changing the value in one block changes in all blocks on the page.
If you want to change the block colors or other things, you have to use block attributes (without the Save in Meta option). And your code will be like this:
<div style="background-color: <?php echo $attributes['background-color'] || 'red'; ?>">Test</div>
Regards,
Nikita.
Thanks, got it. Thought the meta value is per block, makes sense now.