0
4

2 回答 2

0

您必须使用 Wordpress 条件函数is_page()

add_filter( 'the_content', 'attachment_image_link_remove_filter' );
function attachment_image_link_remove_filter( $content ) {
    // Set your exception pages in here
    if( !is_page( array( 42, 48, 55 ) ) ) {
        $content = preg_replace( 
            array('{<a(.*?)(wp-att|wp-content\/uploads)[^>]*><img}',
                '{ wp-image-[0-9]*" /></a>}'),
            array('<img','" />'),
            $content
        );
        return $content;
    }
}

您可以使用页面 ID 或页面 slug,例如"contact-us"……</p>

----(更新添加缺失 ) if( !is_page( array( 42, 48, 55 ) ) ) { ----

于 2016-04-29T12:39:37.570 回答
0

比LoicTheAztec 的答案中提到的ID 更通用的是例如。自定义(元)字段。

function bw_content($content)
{
    if (get_post_meta(get_the_ID(), 'bw_remove_image_links', true) == 1) {
        $content = preg_replace(array(
            '{<a(.*?)(wp-att|wp-content\/uploads)[^>]*><img}',
            '{ wp-image-[0-9]*" /></a>}'
        ), array(
            '<img',
            '" />'
        ), $content);
    }
    return $content;
}
add_filter('the_content', 'bw_content');
于 2016-04-29T12:47:27.430 回答