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

på grund afWordPress artikel automatisk ankertekst plugin Automatiske interne links til SEOEtikettens automatiske ankertekstfunktion understøttes ikke.

Hvis du kan tilføje tag søgeord ankertekst, kan det ikke kunSEOOptimer vores interne links, og tillad også brugere 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?

发表 评论

Din e-mailadresse vil ikke blive offentliggjort. 必填 项 已 用 * 标注

Rul til top