• Resolved ananzeh25

    (@ananzeh25)


    Hi,

    I am trying to remove the image/thumbnail “title and alt attributes”.
    I tried to use this code

    add_filter( 'wp_get_attachment_image_attributes', 'remove_image_text');function remove_image_text( $attr ) {
    unset($attr['alt']);
    unset($attr['title']);
    return $attr;}

    and tried

    add_filter( 'related_posts_by_taxonomy_image_attributes', 'remove_image_text');function remove_image_text( $atts ) {
    unset($atts['alt']);
    unset($atts['title']);
    return $atts;}
    add_filter( 'related_posts_by_taxonomy_image_title', '__return_empty_string' );

    Didn’t work.

    Thanks

    https://www.ads-software.com/plugins/related-posts-by-taxonomy/

Viewing 5 replies - 1 through 5 (of 5 total)
  • Thread Starter ananzeh25

    (@ananzeh25)

    I tried this code too

    add_filter( 'related_posts_by_taxonomy_post_thumbnail_attributes', 'remove_image_text', 10, 2);function remove_image_text( $attributes ) {
    unset($attributes['alt']);
    unset($attributes['title']);
    return $attributes;}

    Plugin Author keesiemeijer

    (@keesiemeijer)

    Hi ananzeh25

    Sorry for the late reply. This should remove the alt attribute from the image.

    add_filter( 'wp_get_attachment_image_attributes', 'remove_image_text' );
    function remove_image_text( $attr ) {
    	unset( $attr['alt'] );
    	return $attr;
    }

    The plugin will be updated somewhere this week. In the new version you can remove the title from the link as well.

    With this in your (child) theme’s functions.php:

    add_filter( 'related_posts_by_taxonomy_post_thumbnail_link', 'remove_related_post_thumbnail_title', 10, 4 );
    function remove_related_post_thumbnail_title( $image, $attr, $related, $args ) {
    	return "<a href='{$attr['permalink']}'>{$attr['thumbnail']}</a>";
    }

    If you need it now you can download the development version 0.4-beta1 from the github repository.
    https://github.com/keesiemeijer/related-posts-by-taxonomy/releases

    btw:
    consider creating a child theme instead of editing your theme directly – if you upgrade the theme all your modifications will be lost. Or create a plugin with the code above.

    Plugin Author keesiemeijer

    (@keesiemeijer)

    Hi ananzeh25
    I’ve updated the plugin. You can now use the filter related_posts_by_taxonomy_post_thumbnail_link in your theme’s functions.php.

    Thread Starter ananzeh25

    (@ananzeh25)

    keesiemeijer

    Thank you for your reply and your code. The plugin and the code are working great.

    Plugin Author keesiemeijer

    (@keesiemeijer)

    You’re welcome. I’m glad it’s working great ??

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Post Image/thumbnail alt and title’ is closed to new replies.