If you are a blogger and make some cash from affiliate marketing then you probably insert affiliate links into the articles on your website, so that you get paid when a visitor purchase a product that you recommended. But if you are just starting out on affiliate marketing and want to insert affiliate link keywords into couple of hundred existing articles on your website then adding links manually in each article is not what you want to spend your time on. Because it’s exhausting and will consume lots of your time to modify all these articles. Rather than inserting these link keywords manually, you want them generated automatically so that all you had to do is specify the link keywords and your affiliate link.
In the past, we wrote about adding meta description tags and nofollow links to improving SEO of your website and in this article we will show you an easy way to automatically link keywords in post content and post excerpt on your WordPress website. Although, when it comes to SEO or affiliate marketing, I would strongly recommend you to use a dedicated plugin but sometimes you want a simpler and quicker solution for your problem. So here is a simple function to insert link keywords in content of your articles automatically.
Just change the keyword and links in following WordPress snippet and paste this into your functions.php file and it will automatically link keywords on your website.
// auto link keywords in post content and excerpt
function wcs_auto_link_keywords( $text ) {
$replace = array(
'wordpress' => '<a href="http://www.wordpress.org">wordpress</a>',
'google' => '<a href="http://www.google.com">excerpt</a>',
'facebook' => '<a href="http://www.facebook.com">function</a>'
);
$text = str_replace( array_keys($replace), $replace, $text );
return $text;
}
add_filter( 'the_content', 'wcs_auto_link_keywords' );
add_filter( 'the_excerpt', 'wcs_auto_link_keywords' );