【问题标题】:How can I remove Links from all gallery images in Wordpress?如何从 Wordpress 中的所有图库图像中删除链接?
【发布时间】:2013-11-14 02:24:12
【问题描述】:

我尝试了几种解决方案,这些解决方案适用于不适合我的其他人。

这是我试图影响的 HTML 示例

<dt class='gallery-icon'>
                <a href='http://localhost/wordpress/?attachment_id=94' title='IMG_6032'>

&lt;a href 必须离开,图像必须留下。

在我的选项中,链接图片设置为关闭。

我读过的解决方案显然不知道 wordpress 中的画廊是什么,因为它与图像列表不同。

update_option('image_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 图库功能会为您的图片添加一个链接,似乎可以绕过这些过滤器。

【问题讨论】:

  • 到目前为止,我最好的解决方案是使用 css 在我的画廊图标类中禁用指针操作,

标签: php html wordpress


【解决方案1】:

我也遇到过几次这个问题。经过一番搜索,最终我找到了一个超级酷的小插件,它可以在使用图库短代码时非常容易地摆脱锚标签。

安装插件并激活它,然后当你插入短代码时,使用这个:[gallery link="none"]。插件激活后,您只需将link="none" 添加到您的图库短代码中

你可以在这里找到插件:http://wordpress.org/plugins/gallery-linknone/

【讨论】:

    【解决方案2】:

    您可以使用functions.php 中的这段代码禁用链接:

    add_shortcode( 'gallery', 'modified_gallery_shortcode' );
    function modified_gallery_shortcode($attr) {
        $attr['link']="none";
        $output = gallery_shortcode($attr);
        return $output; 
    }
    

    这将导致没有 &lt;a&gt; 标记被插入到库 html 输出中。

    【讨论】:

      猜你喜欢
      • 2017-07-23
      • 1970-01-01
      • 2012-07-02
      • 1970-01-01
      • 2015-06-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多