推荐阅读

两种方法实现WordPress内容图片自动加上ALT和TITLE标签
从SEO角度我们需要给文章中的图片添加ALT和TITLE标签的。有些时候我们是不是会忘记?这里我们可以实现自动添加标签。在这篇文章中,老蒋用代码实现WordPress内容图片自动加上TITLE和ALT标签办法。 1、方法一 function image_alttitle( $imgalttitle ...
日期:2021/11/5
阅读全文
第一、编辑器当前主题
function imgAlt(&$template){
global $zbp;
$article = $template->GetTags('article');
$pattern = "/<img(.*?)src=('|\")([^>]*).(bmp|gif|jpeg|jpg|png|swf)('|\")(.*?)>/i";
$replacement = '<img alt="'.$article->Title.'" src=$2$3.$4$5/>';
$content = preg_replace($pattern, $replacement, $article->Content);
$article->Content = $content;
$template->SetTags('article', $article);
}在当前主题的include.php 最后一行之前加上代码。
第二、添加接口文件
同样在当前文件的ActivePlugin_Tctitleseo()部分添加接口。
Add_Filter_Plugin('Filter_Plugin_ViewPost_Template','imgAlt');这样我们就可以实现当前主题中,添加的图片自动加上ALT属性。