Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Contributor Martin Stehle

    (@hinjiriyo)

    There is no such filter. What should the filter change? The IMG code?

    Thread Starter TheHungryGeek

    (@thehungrygeek)

    Quoting from that plugin’s documentation:

    The rwp_add_filters filter allows you to add additional filters (confusing, I know) that RWP should be applied on.
    RWP is by default applied to the post_thumbnail_html and the_content filters. Any images found inside these filters will be made responsive.

    That 3rd plugin’s filter attaches to filters containing images and makes them responsive by adding the relevant srcsets, and unlike the WordPress native responsive support, there is no aspect ratio lock.

    So far this has worked with all the filters in my theme that filter the HTML mark-up of the relevant sections with images. It has also worked with e.g. Contextual Related Post’s crp_get_the_post_thumbnail that filters the post thumbnail created by that plugin.

    I guess I’m out of luck here?

    Plugin Contributor Martin Stehle

    (@hinjiriyo)

    I will take a look and inform you.

    Plugin Contributor Martin Stehle

    (@hinjiriyo)

    The attributes ‘srcset’ and ‘sizes’ are already included in the plugin. If you choose an image size greater than ‘thumbnail’ those attributes are added to the thumbnails automatically.

    Thread Starter TheHungryGeek

    (@thehungrygeek)

    Hi Martin,

    Unfortunately your plugin uses the native WordPress responsive feature which will only add the srcsets when the image aspect ratios are identical (or extremely close).

    So for my image size selection right now no srcsets are included, requiring the need for a different plugin to include it.

    Edit: Also, I just tested the plugin with the standard ‘large’ WordPress image size and the smaller srcsets (e.g. medium and thumbnail) were not included.

    Plugin Contributor Martin Stehle

    (@hinjiriyo)

    Because of the use of the native WordPress responsive feature you can use the filter hook wp_get_attachment_image_attributes to add more attributes to the IMG element. The documentation in the function wp_get_attachment_image() says:

    /**
    * Filter the list of attachment image attributes.
    *
    * @since 2.8.0
    *
    * @param array        $attr       Attributes for the image markup.
    * @param WP_Post      $attachment Image attachment post.
    * @param string|array $size       Requested size. Image size or array of width and height values
    *                                 (in that order). Default 'thumbnail'.
    */
    $attr = apply_filters( 'wp_get_attachment_image_attributes', $attr, $attachment, $size );

Viewing 6 replies - 1 through 6 (of 6 total)

The topic ‘Filter for image thumbnail’ is closed to new replies.