Support

Account

Home Forums ACF PRO Background-color on flexible fields

Solved

Background-color on flexible fields

  • Hi,

    I have flexible content fields as modules. For the content-repeater module I would like to have the option for a background-color. This is optional.

    I tried this with the colorpicker. I can get the value of the HEX color, but this color is for all the content-repeater module on that page.
    So If I have 2 content-repeater modules on that page, i see the background-color for the last chosen color.

    Let say for the first content-repeater module I choose the color red as background. For the second content-repeater module I choose the green color as background. Now for both content-repeater modules the background is green and not red and green.

    What i’m doing wrong or better….howto fix the issue?

    Thanks in advnaced.

    regards,
    Roland

  • What code are you using to set the background color of the element?

  • Hi John,

    In page-template.php

    Background is a colorpicker ACF field

    <?php 
    $background = get_sub_field('background');
    ?>
    
    <section class="content <?php echo $background ?>">
       <p> --------</p>
    </section>
  • I don’t think I understand enough by looking at the code you provided.

    
    <?php 
    $background = get_sub_field('background');
    ?>
    
    <section class="content" style="background-color: <?php echo $background; ?>">
       <p> --------</p>
    </section>
    
  • Hi John,

    I feel so stupid. Ofcourse I have to add the style= in front of it.

    Thanks

Viewing 5 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic.