WordPress.org

Support

Support » How-To and Troubleshooting » [Resolved] Hide Alt Title on Thumbnail Mouseover

[Resolved] Hide Alt Title on Thumbnail Mouseover

Viewing 12 replies - 1 through 12 (of 12 total)
  • Moderator Kathryn

    @zoonini

    Automattic Happiness Engineer

    Those are coming from the title attribute on the img tag.

    I don’t know how you’re generating your thumbnails, but if you can access the code directly, just remove all the title attributes.

    For example, remove title="1193528_95902129" from this:

    <img width="150" height="150" src="http://www.filedcontent.com/wp-content/uploads/2011/06/1193528_95902129-150x150.jpg" class="attachment-thumbnail" alt="1193528_95902129" title="1193528_95902129" /></a>

    Incidentally, I strongly recommend that you make the alt tags something descriptive so that visually impaired people and those who have turned off images will get a description of the image instead of just a number.

    Thx zoo! Anyone else??

    You could try the javascript way. This example with jquery :

    First, in the header.php file of your theme, add this code the line before the closing head tag (</head>) :

    <!-- include the latest version of jQuery-->
    <script src="http://code.jquery.com/jquery-latest.js"></script>

    (only if your theme isn’t already using jQuery)

    Then, add this code to the footer.php file of your theme :

    <script type="text/javascript">
    /* The first line waits until the page has finished to load and is ready to manipulate */
    $(document).ready(function(){
        /* remove the 'title' attribute of all <img /> tags */
        $("img").removeAttr("title");
    });
    </script>

    Yeah. As simple as that.

    Thx Kraignos! This is an excellent alternative!

    Yep, very straightforward 🙂
    Be aware though, that as this is javascript based, people who turned Javascript off in their browser config will still see the titles on rollover. Don’t have the stats but it shouldn’t be a bunch of people…

    When you insert the image into a post you get the option to edit the title. This can be edited after you post too, so just go back into each post and edit those images!

    petervandoorn is right, this would be the best and cleaner way to do this. And not so long if you don’t have many pics.

    No javascript required:

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

    I tried the method posted by “bfred.it” with no luck. I added the function to my “functions.php” but it had no effect on any of my pages. Please let me know if I’m missing something or I will just have to stick with the jQuery .removeAttr function. Thanks.

    negrelja, it worked for me just now

    Mark

    @markurbaninteractiveus

    negrelja, that kinda works with twenty eleven, but instead of the title now the rollover reads “Permalink to *title of post*”. Just an fyi…

    Kraignos, I know it’s an old topic but thank you! Worked like a dream.

Viewing 12 replies - 1 through 12 (of 12 total)
  • The topic ‘[Resolved] Hide Alt Title on Thumbnail Mouseover’ is closed to new replies.
Skip to toolbar