• Hi,

    I’m using Timber successfully on a live site.

    I wanted to improve post thumbnails by using a plugin called WP Smartcrop. The plugin allows you to set a custom focal point within an image, which will then be used to dynamically reposition the image responsively. Plugin demo here.

    For the plugin to fully work, it needs its classes to be applied to an <img> tag. Using a standard WP-way of rendering an image, I can get the plugins’ classes to appear on the <img> tag:

    Regular WP-way of calling an image (in theme):

    wp_get_attachment_image(image_id, "medium")

    With output looking like:

    <img class="attachment-medium size-medium wpsmartcrop-image" ...

    Problem:
    I’m using Timber for everything, including rendering thumbnails, and different classes are being outputted with no “wpsmartcrop”-related classes.

    Calling images in Timber like so:

    <img class="{{ post.thumbnail.class }}" src="{{ post.thumbnail.src('medium') }}" srcset="{{ post.thumbnail.srcset }}" sizes="{{ post.thumbnail.img_sizes }}" alt="{% if post.thumbnail.alt %} {{ post.thumbnail.alt }} {% else %}Book cover image{% endif %}"/>

    and getting output like so:

    <img class="post-3445 attachment type-attachment status-inherit hentry" ...

    Should I be getting classes differently? Is this a case of grabbing classes for an post attachment vs actual image attachment?

    Thx

  • The topic ‘Getting classes from media attachment’ is closed to new replies.