So richten Sie interne Links in WordPress ein Automatisches Hinzufügen von Ankertext zu Inhalts-Tags von Artikeln

durchWordPress-Artikel Automatisches Ankertext-Plugin Automatische interne Links für SEODie automatische Ankertextfunktion des Labels wird nicht unterstützt.

Wenn Sie Tag-Schlüsselwort-Ankertext hinzufügen können, kann es nicht nurSEOOptimieren Sie unsere internen Links und ermöglichen Sie Benutzern auch, auf verwandte Artikel zu verweisen.

WordPressWie fügen Tags automatisch interne Links hinzu?

So richten Sie interne Links in WordPress ein Automatisches Hinzufügen von Ankertext zu Inhalts-Tags von Artikeln

Wie kann man also den Artikeln auf der WordPress-Website automatisch interne Links hinzufügen?

Eigentlich müssen wir nurfunctions.phpFügen Sie in der Datei ein Stück PHP-Code hinzu, um dies zu erreichen.

WordPress-Post-Content-Tags fügen automatisch Ankertext-Innenlinks hinzu

/**
* WordPress文章内容标签自动加锚文本内链
* https://www.chenweiliang.com/cwl-27651.html
**/
function wptag_auto_add_anchor_text_link($content){

$limit = 1; // 设置WordPress文章同一个标签,自动添加几次内链?

$posttags = get_the_tags();

if ($posttags) {
foreach($posttags as $tag) {
$link = get_tag_link($tag->term_id);
$keyword = $tag->name;

$cleankeyword = stripslashes($keyword);
$url = '<a target="_blank" href="'.$link.'" title="'.str_replace('%s', addcslashes($cleankeyword, '$'), __('View all posts in %s')).'">'.addcslashes($cleankeyword, '$').'</a>';
$regEx = '\'(?!((<.*?)|(<a.*?)))('. $cleankeyword . ')(?!(([^<>]*?)>)|([^>]*?</a>))\'s';
$content = preg_replace($regEx,$url,$content,$limit);
}
}

return $content;
}
add_filter( 'the_content', 'wptag_auto_add_anchor_text_link', 1 );

Code zu WordPress hinzufügenThemafunctions.phpLesen Sie nach der Datei unseren Artikel erneut.

Werden interne Links automatisch hinzugefügt, wenn die von uns hinzugefügten Tag-Keywords erscheinen?

发表 评论

Ihre E-Mail-Adresse wird nicht veröffentlicht. 必填 项 已 已 * 标注

Nach oben scrollen