Problem with adding custom CSS class to image
-
Hi, I have a problem with adding custom CSS class to image.
I added following code to functions.php file: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) ); return $args; } add_filter( 'acf_photo_gallery_image_fields', 'my_extra_gallery_fields', 10, 3 );
next code in single-portfolio.php:
<?php $images = acf_photo_gallery('gallery_images', $post->ID); if( count($images) ): foreach($images as $image): $full_image_url= $image['full_image_url']; $class = get_field('gallery_images_class', $id); endforeach; endif; ?>
and display this variable:
<?php foreach($images as $image) { ?> <img src="<?php echo $image['full_image_url']; ?>" class="<?php echo $class; ?>" > <?php } ?>
Nothing happend. I mean I see in admin field to enter CSS class, but it does not show up in the code. What I am doing wrong?
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- The topic ‘Problem with adding custom CSS class to image’ is closed to new replies.