开发者

Problems Removing ALT/TITLE Tooltip - WordPress Theme

I installed a theme called "Mansi开发者_运维知识库on" (the free version) by Graph Paper Press on my own WordPress blog. Everything's running smoothly, but I'd like to remove, disable, or otherwise keep the ALT and TITLE tooltips from appearing on the user-end.

WordPress automatically generates the TITLE attribute from the file name when uploading images if you leave the field blank. Furthermore, both TITLE and ALT are automatically generated by a script called "Get the Image" (Justin Tadlock) on this theme, and I'm unfortunately not comfortable enough with the code to disable just that aspect of it (I need it for the theme to run).

I've tried a variety of jQuery scripts to hide or remove the attributes to absolutely no avail, and I'm beginning to think it might be a quirk related to the theme itself. Does anyone have any ideas? My blog is located at http://www.ikukawachi.com/cvj341/wordpress/.


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;
}


So long as you have jQuery available, you could try:

$('img[title], img[alt]').removeAttr('title').removeAttr('alt');

This works in the console of Chromium 10 on Ubuntu 10.10.


Edited in response to comment by @Iku:

Hi, thanks for the help. Unfortunately, I made sure I enqueued the built-in jQuery library and added the code you suggested, and it still doesn't seem to be working. (It's in the source, if you'd like to look at the site.) This may seem like a dumb question, but does the code need to be placed in a specific location on the page for it to work? If so, where?

The jQuery, above, should be located inside either:

$(document).ready(
    function(){
        $('img[title], img[alt]').removeAttr('title').removeAttr('alt');
    });

Or:

$(window).load(
    function(){
        $('img[title], img[alt]').removeAttr('title').removeAttr('alt');
    });

The difference between the two is that $(document).ready() occurs when the DOM is loaded, and ready; whilst $(window).load() occurs once the resources linked to on the page, such as img elements, have been loaded.

To test your browser, open the JavaScript console (ctrl + shift + i in Chrome/Chromium/Safari), and paste the following into the console:

var s = document.createElement('script'); s.src = 'https://ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js'; document.getElementsByTagName('head')[0].appendChild(s);

Hit enter, and then paste the following:

$('img[title], img[alt]').removeAttr('title').removeAttr('alt');

After this you should be able to hover any img element and see no title, and in the place of a missing image the alt should not be shown.

References:

  • attribute-equals selector.
  • removeAttr().
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜