您想从单篇文章中删除样式。“单一职位”一词令人困惑。无论您是需要用于单个帖子还是单个帖子模板。
无论哪种情况,您都必须将代码与条件一起使用,您的代码可能如下所示。
If you want to remove from all posts(not pages but including custom post types).
add_filter( \'the_content\', function( $content ){
if(is_single()){
return str_replace( \' style="\', \' data-style="\', $content);
}
else{
return $content;
}
});
If you want to remove from all posts(only WordPress post, not custom post type or pages).
add_filter( \'the_content\', function( $content ){
if (is_singular(\'post\')) {
return str_replace( \' style="\', \' data-style="\', $content);
}
else{
return $content;
}
});
is_singular
WordPress API是否有条件检查帖子类型。
https://developer.wordpress.org/reference/functions/is_singular/ If you want to remove from only one particular post.
add_filter( \'the_content\', function( $content ){
if(is_single([POST-ID])){
return str_replace( \' style="\', \' data-style="\', $content);
}
else{
return $content;
}
});