I am using the ACF Photo Gallery plugin (ACF addon that adds an image gallery option). I’m trying to add the option of giving my own CSS class to a particular image, all by the tutorial -> https://wordpress.org/plugins/navz-photo-gallery/ (Usage, Add Extra Field), but unfortunately for some reason the CSS class does not appear In the code. I paste below my comment code (there is not much). Where did I make a mistake?

/// I put this to functions.php, in edition in particular image window appears with css class field
<?php
function my_extra_gallery_fields( $args, $attachment_id, $field ){
    $args['class'] = array('type' => 'text', 'label' => 'Kolor produktu', 'name' => 'class', 'value' => get_field($field . '_class', $attachment_id) );  /// I think the problem may be here
    return $args;
}
add_filter( 'acf_photo_gallery_image_fields', 'my_extra_gallery_fields', 10, 3 );
?>
/// I put this code to single-portfolio.php
<?php
    $images = acf_photo_gallery('gallery_images', $post->ID); /// gallery_images to slug pola galeria w ACF
    if( count($images) ):
        foreach($images as $image):
            $full_image_url= $image['full_image_url'];
            $class = get_field('gallery_images_class', $id);
    endforeach; endif;
?>  
/// This code displays image, CSS class should appers, but it doesn't
<?php foreach($images as $image) { ?>
     <img src="<?php echo $image['full_image_url']; ?>" class="<?php echo $class; ?>" >
<?php } ?>

Read more here: Problem with adding custom CSS class to image in ACF Photo Gallery plugin


Solution:

If you know the solution of this issue, please leave us a reply in Comment section, to update the question.


Wordpress related questions and answers: