简体   繁体   English

如何从Wordpress中的图像中删除标题属性?

[英]How do I remove the title attribute from images in Wordpress?

My client is not too crazy about the tooltip you see when you hover on images in browsers like Safari. 当您将鼠标悬停在Safari这样的浏览器中的图像上时,我的客户并不为您看到的工具提示而疯狂。 在此处输入图片说明

The tooltip displays the title attribute in the img tag, which Wordpress forces you to have. 工具提示会在img标签中显示title属性,Wordpress会强制您具有此属性。 Removing the title value from the tag (easy to do with jQuery) still shows you a blank tooltip. 从标记中删除标题值(易于使用jQuery)仍然显示空白的工具提示。

So I don't need a solution that does this: 因此,我不需要执行此操作的解决方案:

<img title=" " src="foobar.png" />

I need a solution that does this : 我需要一个可以做到这一点的解决方案:

<img src="foobar.png" />

I have searched all over the Internet, and the answers that come close don't seem to work. 我已经在Internet上进行了搜索, 但是接近的答案似乎无效。 I believe it can be done by overriding the Wordpress core function that generates the image tags. 我相信可以通过重写生成图像标签的Wordpress核心功能来完成。

If you want a straight JavaScript solution this should work: 如果您想要直接的JavaScript解决方案,则可以使用:

var imgs = document.getElementsByTagName('img');
for (var i = 0; i < imgs.length; i++) {
  imgs[i].removeAttribute('title');
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM