Sådan opsætter du interne links i WordPress? Tilføj automatisk ankertekst til artikelindholdstags

WordPress -pluginnet Automatiske interne links til SEO understøtter ikke automatisk ankertekst til tags.

Tilføjelse af tag-søgeord og ankertekst optimerer ikke kun vores interne links til SEO , men giver også brugerne mulighed for at henvise til relaterede artikler.

hood.discountHvordan tilføjer tags automatisk interne links?

Sådan opsætter du interne links i WordPress? Tilføj automatisk ankertekst til artikelindholdstags

Så hvordan får man artiklerne på WordPress-webstedet til automatisk at tilføje tag interne links?

Det behøver vi faktisk kunfunctions.phpTilføj et stykke php-kode i filen for at opnå det.

WordPress Postindholdstags Tilføj automatisk ankertekst indre links

/**
* 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 );

Tilføj kode til WordPressTemafunctions.phpEfter filen, læs vores artikel igen.

Er der en automatisk tilføjelse af interne links, når de tag-nøgleord, vi tilføjer, vises?

发表 评论

您的邮箱地址不会被公开。必填项已用*标注

Rul til top