How to set up internal links in WordPress? Automatically add anchor text to article content tags

due toWordPress article automatic anchor text plugin Automatic Internal Links for SEOThe label's automatic anchor text feature is not supported.

If you can add tag keyword anchor text, it can not onlySEOOptimize our internal links, and also allow users to refer to related articles.

WordPressHow do tags automatically add internal links?

How to set up internal links in WordPress? Automatically add anchor text to article content tags

So how to make the articles on the WordPress website automatically add tag internal links?

In fact, we only need tofunctions.phpIn the file, add a piece of php code to achieve it.

WordPress Post Content Tags Automatically Add Anchor Text Inner 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 );

Add code to WordPressThemefunctions.phpAfter the file, read our article again.

Is there an automatic addition of internal links when the tag keywords we add appear?

Hope Chen Weiliang Blog ( https://www.chenweiliang.com/ ) shared "How to set up internal links in WordPress? Automatically add anchor text optimization to article content tags", which is helpful to you.

Welcome to share the link of this article:https://www.chenweiliang.com/cwl-27651.html

Welcome to the Telegram channel of Chen Weiliang's blog to get the latest updates!

🔔 Be the first to get the valuable "ChatGPT Content Marketing AI Tool Usage Guide" in the channel top directory! 🌟
📚 This guide contains huge value, 🌟This is a rare opportunity, don’t miss it! ⏰⌛💨
Share and like if you like!
Your sharing and likes are our continuous motivation!

 

Comment

Your email address will not be published. Required fields * Callout

scroll to top