【问题标题】:Remove/Edit Img classes in Wordpress在 Wordpress 中删除/编辑 Img 类
【发布时间】:2012-08-23 20:52:35
【问题描述】:

所以 Wordpress 正在输出这个

<img src="http://site.com/path/to/image.png"; alt="Text"  width="600" height="100" class="alignnone size-full wp-image-168" />

但是,我希望它输出这个

<img src="http://site.com/path/to/image.png"; alt="Text"  width="600" height="100" class="full wp-image-168" />

移除 align 类并移除 size- 部分。

如何通过 functions.php 文件中的过滤器来解决这个问题?

【问题讨论】:

    标签: php image wordpress class


    【解决方案1】:

    所以这里有几个过滤器可以满足你的需要。

    add_filter( 'post_thumbnail_html', 'remove_image_classes', 10 );
    add_filter( 'image_send_to_editor', 'remove_image_classes', 10 );
    
    function remove_image_classes( $html ) {
        $html = preg_replace( '/(size-|alignnone)/', "", $html );
        return $html;
    }
    

    我不知道我的 preg_replace 是否正确。试试看它是否会修改您的代码。

    【讨论】:

    • 感谢您的回复。不幸的是,这什么也没做。
    • 我想知道这是不是因为我没有在我的代码中使用 post_thumbnails?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-02-02
    • 1970-01-01
    • 1970-01-01
    • 2012-08-19
    • 2017-11-27
    • 2014-03-04
    • 1970-01-01
    相关资源
    最近更新 更多