• Resolved lindagustavsson

    (@lindagustavsson)


    Is it possible to add a class to both of my featured images?

    It would allow me to swiftly hide/display the featured images via a change in css.

    For example if I want to use Featured image A during summer, and Featured image B during winter.

Viewing 1 replies (of 1 total)
  • Plugin Author Marcus Kober

    (@marcuskober)

    Hi there,

    sure, there are several ways to add classes to your featured images.

    1) Use wp_get_attached_image

    You could get the id of your featured image for using it in the WordPress function wp_get_attached_image.

    
    $myId = kdmfi_get_featured_image_id( 'featured-image-2' );
    
    echo wp_get_attached_image($myId, 'full', false, ['class' => 'my-class']);
    

    2) Shortcode

    You could use the shortcode.

    Shortcode usage:

    [kdmfi_featured_image id=”featured-image-2″ size=”full” class=”your-class”]

    Possible attributes for the shortcode:

    id: the id of the featured image, e.g. featured-image-2, requried
    size: the desired size, defaults to “full”
    post_id: the ID of the post to which the featured image is assigned, defaults to the current ID
    class: the classes for the image tag, defaults to “kdmfi-featured-image”
    alt: the alt attribute for the image tag, defaults to the title of the used image
    title: the title attribute for the image tag, empty by default

    Regards,
    Marcus

Viewing 1 replies (of 1 total)
  • The topic ‘Add class to each image’ is closed to new replies.