我已经尝试了几种对其他人有效的解决方案,但这些解决方案并不适合我。
以下是我试图影响的HTML示例
<dt class='gallery-icon'>
<a href='http://localhost/wordpress/?attachment_id=94' title='IMG_6032'>
<a href
必须离开,图像必须保留。
在我的选项中,链接图像被设置为关闭。
我读过的解决方案显然不知道wordpress中的图库是什么,因为它与图像列表不同。
update_option('images_default_link_type','none');
没用。
这个也没有
function attachment_image_link_remove_filter( $content ) {
$content =
preg_replace(
array('{<a(.*?)(wp-att|wp-content/uploads)[^>]*><img}',
'{ wp-image-[0-9]*" /></a>}'),
array('<img','" />'),
$content
);
echo $content;
return $content;
}
或者这个
function my_gallery_to_slideshow_settings( $params ){
$params['link'] = 'file';
return $params;
}
当我添加过滤器时,什么也没发生。
默认的wordpress Gallery功能为您的图像添加了一个链接,该链接似乎绕过了这些过滤器。
我也遇到过几次这个问题。它花了一些搜索,但最终我找到了一个超级酷的小插件,它可以在使用图库快捷代码时非常容易地去除锚标签。
安装插件并激活它,然后当你插入快捷代码时,使用这个:[gallery link="none"]
。插件激活后,您所要做的就是将link="none"
添加到您的图库快捷代码中
你可以在这里找到插件:http://wordpress.org/plugins/gallery-linknone/
您可以在functions.php
:中使用这段代码禁用链接
add_shortcode( 'gallery', 'modified_gallery_shortcode' );
function modified_gallery_shortcode($attr) {
$attr['link']="none";
$output = gallery_shortcode($attr);
return $output;
}
这将导致没有<a>
标记插入到库html输出中。