个性化阅读
专注于IT技术分析

在WYSISWG编辑器中将类添加到图像(高级自定义字段/ WordPress)

点击下载

我想为我在”高级自定义字段”的WYSISWG编辑器字段中发布的每个图像添加一个类。除其他编辑器类外, 每个图像还应具有img-fluid类。

如果我在普通的WordPress编辑器中添加了图像, 我就设法添加了该类。这是我的functions.php中的代码:

/* Add img-fluid to images in the_content */
function add_image_responsive_class($content) {
   global $post;
   $pattern ="/<img(.*?)class=\"(.*?)\"(.*?)>/i";
   $replacement = '<img$1class="$2 img-fluid"$3>';
   $content = preg_replace($pattern, $replacement, $content);
   return $content;
}
add_filter('the_content', 'add_image_responsive_class');

但是该代码不适用于”高级自定义字段”的WYSISWG编辑器字段。还有其他方法可以处理内容中的图像吗?


#1


你还应该使用过滤器acf_the_content启动操作, 它应该可以正常运行(https://www.advancedcustomfields.com/resources/wysiwyg-editor/)

赞(0)
未经允许不得转载:srcmini » 在WYSISWG编辑器中将类添加到图像(高级自定义字段/ WordPress)

评论 抢沙发

评论前必须登录!