Support

Account

Home Forums General Issues Add class to acf fields Reply To: Add class to acf fields

  • I have the same problem but on flexible layouts fields.

    i would like to make some customized css for different layouts of the same repeater.

    I ended up adding some jquery to get the data-layout attribute from repeater layout row and using it as css class to the very same element.
    So you’ll have different classes for different repeater layouts, based on the layout name.

    this is the small script I’ve done, nothing special but it works.

    jQuery.noConflict()(function($){
        "use strict";
         $(document).ready(function() {
            var layouts = $('.acf-flexible-content .layout');
            layouts.each(function( key, value ) {
    
                    var section_attribute = $(this).attr('data-layout');
    
                    $(this).addClass(section_attribute);
    
            });
    
        });
    });

    Would be surely better if this classes were built in ACF PRO