如何从图库链接和图像中删除标题属性

时间:2012-09-11 作者:bigandy

我想从[图库]短代码的输出中删除title属性,例如。

<a href="url" title="bobby">
   <img src="url" title="bobby"/>
</a>
应为:

<a href="url" >
   <img src="url" />
</a>
我觉得这和wp_get_attachment_link 作用

1 个回复
SO网友:bigandy

我找到了一个解决方案:

// Remove &lt;img&gt; title attribute in [gallery]
// http://wordpress.org/support/topic/wp_get_attachment_image_attributes-filter-not-working
function remove_img_title($atts) {
    unset($atts[\'title\']);
    return $atts;
}
add_filter(\'wp_get_attachment_image_attributes\',\'remove_img_title\', 10, 4);

// remove title attribute from &lt;a&gt; title attribute in [gallery]
// modified from this post : http://oikos.org.uk/2011/09/tech-notes-using-resized-images-in-wordpress-galleries-and-lightboxes/
function ah_get_attachment_link_filter( $content ) {       

        $new_content = preg_replace(\'/title=\\\'(.*?)\\\'/\', \'\', $content );
        return $new_content;
}
add_filter(\'wp_get_attachment_link\', \'ah_get_attachment_link_filter\', 10, 4);

结束

相关推荐

Problem uploading images

多站点3。4.1 wordpress我用htaccess规则重定向了wp admin,并通过wp config重命名了wp内容和插件http://codex.wordpress.org/Editing_wp-config.php#Moving_wp-content现在我不能再上传图片了。当我尝试上载图像时,它会开始处理,但随后出现http错误,或者说您确定要这样做,但不允许我上载图像。this is in .htacess RewriteEngine On RewriteBase /