Home Forums Gutenberg Custom css for Gutenberg Block Reply To: Custom css for Gutenberg Block

  • Hi, @simow
    I do not know any way to make CSS recognize PHP unless it uses some plugin or framework. For your problem I would recommend creating a <style> tag on the page or adding a "style" in the element.

    Using the example of the <style> tag would look like this:

    #<?php echo $id; ?> {
    background: <?php the_field('background_color'); ?>;
    color: <?php the_field('text_color'); ?>;

    or creating a direct style in the element, something like this:

    if(get_field('background_color') or get_field('text_color')) { $style = 'style="background:'. get_field('background_color') .'; color:'. get_field('text_color') .';"'; }
    <!-- Add style in my div -->
    <div <?php echo $style; ?>>
    lorem ipsum test

    I hope it helps!