WordPress.org

Support

Support » How-To and Troubleshooting » Remove title= attribute from the_post_thumbnail

Remove title= attribute from the_post_thumbnail

  • If I do a call for a thumbnail:

    <?the_post_thumbnail();?>

    It brings back something like this:

    <img width="125" height="80" src="image.jpg" class="attachment wp-post-image" alt="Hello World!" title="Hello World!" />

    Where can I find the code so it does not output the title= aspect of the image call? I’m using a tooltip on the images and would prefer that title doesn’t interfere with it.

Viewing 9 replies - 1 through 9 (of 9 total)
  • It is better to add a filter, not changing the core WordPress code. WordPress is very flexible, so that you can filter almost anything, including the post_thumbnail.

    Put the filter code in functions.php of your theme file. The filter name is post_thumbnail_html.

    add_filter('post_thumbnail_html', 'thumbnail_filter', 99, 5);
    
    function thumbail_filter($html, $post_id, $post_thumbnail_id, $size, $attr) {
       // you can alter the resulted HTML here
       $html = // remove title from $html
       return $html;
    }
    

    or you can implement the wp_get_attachment_image_attributes filter, and unset the title attribute. But this method, will eliminate title attribute in all images (not just thumbnail).

    Hi guys. I’m having a similar issue.. I’d like to get rid of the size attributes, so I can control the sizes with CSS instead. Suhanto, I assume what you posted is a part of it, but I can’t really figure out the rest.

    Any hints are appreciated!

    Suhato – thanks for the tips, still a bit over my head though. I’d still like to know where the actual code is that outputs the HTML that way I can copy it in your above code in the $html variable…and then modify to fit my needs. Hope that makes sense?

    Has anybody got an answer to this, as I am too am stuck!

    I tried locating the post thumbnail template but there was no mention fo title in there.

    Can somebody please help me with this. I have even tried masking the image with another anchored div, still showing though!

    Yep, me too!

    Anyone figured it out yet? I just want to use the post title instead of the featured image title on hover.

    <?php the_post_thumbnail(array('title' => "")); ?>

    More info here: http://codex.wordpress.org/Function_Reference/the_post_thumbnail

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Remove title= attribute from the_post_thumbnail’ is closed to new replies.