WordPress.org

Ready to get started?Download WordPress

Forums

Remove title= attribute from the_post_thumbnail (10 posts)

  1. Dave P.
    Member
    Posted 3 years ago #

    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.

  2. Agus Suhanto
    Member
    Posted 3 years ago #

    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).

  3. asgeirhoem
    Member
    Posted 3 years ago #

    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!

  4. Dave P.
    Member
    Posted 3 years ago #

    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?

  5. narkiej
    Member
    Posted 3 years ago #

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

  6. narkiej
    Member
    Posted 3 years ago #

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

  7. narkiej
    Member
    Posted 3 years ago #

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

  8. akdonovan
    Member
    Posted 3 years ago #

    Yep, me too!

  9. dikkevandale
    Member
    Posted 3 years ago #

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

  10. themolitor
    Member
    Posted 3 years ago #

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

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

Topic Closed

This topic has been closed to new replies.

About this Topic