WordPress图片怎么自动添加alt和title属性,将下面代码添加到当前WordPress模板函数functions.php中即可。
/** WordPress图片自动添加alt和title属性*/
function image_alt_title($content){
global $post;preg_match_all('/<img (.*?)\/>/', $content, $images);
if(!is_null($images)) {foreach($images[1] as $index => $value)
{
$new_img = str_replace('<img', '<img alt="'.get_the_title().'-'.get_bloginfo('name').'"'.'title="'.get_the_title().'-'.get_bloginfo('name').'"', $images[0][$index]);
$content = str_replace($images[0][$index], $new_img, $content);}}
return $content;
}
add_filter('the_content', 'image_alt_title', 99999);
-
WordPress 6.5 新功能 - 字体库字体库是 WordPress 6.5 的亮点之一
-
WordPress6.5新功能-声明式插件依赖在 WordPress 6.5 中,插件依赖变简单了
-
WordPress 6.5 新功能 - 支持 AVIFWordPress 6.5 新功能 - 支持 AVIF
-
WordPress 6.5移除区块样板菜单项的方法WordPress 6.5新增的区块样板菜单项,可将不同区块组合成一个新的区块模板,方便重复使用。
-
WordPress做多语言企业网站近期常用小伙伴问追格小编,有没有计划做双语WordPress企业官网主题。
-
WordPress插件:LiteSpeed Cache 缓存插件LiteSpeed Cache是一款实用的WordPress缓存插件,专为使用LiteSpeed服务器的用户设计。它能显著提高网站加载速度,改善用户体验。
暂无评论,抢个沙发...