Manchester Web Design | SquareNet Media
Single Blog Post

How to Auto Link Keywords in Post Content And Excerpt

by SquareNetMedia Web Developer

Posted on December 24, 2016 at 12:26 PM

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 sq2net_auto_link_keywords( $text ) {
$replace = array(
'wordpress' => 'wordpress',
'google' => 'excerpt',
'facebook' => 'function'
$text = str_replace( array_keys($replace), $replace, $text );
return $text;
add_filter( 'the_content', 'sq2net_auto_link_keywords' );
add_filter( 'the_excerpt', 'sq2net_auto_link_keywords' );

In: Wordpress

About the Author


We are a small team based in Manchester, UK and have been around for over 15 years. We are passionate about web design and development. We have experience with eCommerce, Wordpress, Magento, Search Engine Optimisation, Web Hosting, Google Analytics, HTML, jQuery and much more.


How to Add A Favicon To Your WordPress Website

Posted on Dec 24 2016 at 1:07 pm

Favicons, short for favorite icons, are a small but significant part of branding a website. [...]

Read More
Contact 7

Restricting Contact 7 to Only Load its CSS and JS on Selected Pages

Posted on Nov 26 2016 at 10:18 am

Contact 7 can manage multiple contact forms, plus you can customise the form and the [...]

Read More

Packaging Plugins With Your WordPress Theme Using TGM Plugin Activation Library

Posted on Nov 20 2016 at 1:28 pm

When you’re shipping your theme for sell, it’s often required to bundle the required plugins. [...]

Read More