Mask Affiliate Links With A Plugin You’re Already Using

WordPress SEO by Yoast is one of the most popular WordPress plugins available. However, there is a feature inside of the plugin that can easily be overlooked. The reason for that is because by default the advanced options are turned off. In this article I am going to walk you through how to take advantage of the 301 Redirect feature inside of the plugin, and some other custom WordPress code in order to create affiliate masked links.

The reason I came up with this solution is simple.  I have never been happy with redirection or affiliate masking plugins. For me, they all either didn’t work or had too much going.  So when brainstorming a different approach I realized that WordPress had the answer right in front of me.

By using a Custom Post Type and WordPress SEO by Yoast, I am able to create affiliate masking links easily.  Please note that this tutorial is for advanced users of WordPress who understand how to customize a child theme.  Here is how I went about it:

Step 1: Enable Advanced

The first step is to enable the Advanced part of WordPress SEO by Yoast.  To do so, go the plugin’s Dashboard and uncheck the option to disable Advanced.

Mask Affiliate Links With A Plugin You're Already Using

Step 2. Custom Post Type

I created a simple Custom Post Type and included it within my child theme’s functions.php folder.  What this is doing is creating a Recommends post type, with the function of a page rather than a post.  It provides the option to create a title of the affiliate, a custom slug and include the WordPress SEO by Yoast box.  Since no content is needed, the CPT removes the box.

Step 3. Stop Crawling

The third step is to tell search engines that the new CPT should not be indexed or followed.  Visit the Titles & Metas tab inside of the SEO plugin, and click on Post Types.

Mask Affiliate Links - WordPress SEO Titles Meta

From there, scroll down to the new CPT and click the checkbox that says noindex, follow.

Mask Affiliate Links

Step 4. Sitemap

At this point you have blocked search engines from finding your CPT, but it is still included in the XML sitemap.  So visit the Sitemap options in the SEO plugin and scroll down to the Exclude post types section.

Mask Affiliate Links With A Plugin You're Already Using

Check the new CPT to exclude it from the sitemap, and now you have completely hidden all masked affiliate links from search engines.

Step 5. Recommend

Now that you’ve gone through all the more difficult steps, here is how to create a new masked affiliate link.

  1. Enter the name of the affiliate program, like you would for any blog post or page.
  2. Edit the slug for readability.  I usually remove hyphens when an affiliate has more than one word, but it’s all user preference.
  3. Click on the Advanced tab inside fo the WordPres SEO by Yoast box.
  4. Add the affiliate link under the 301 Redirect section.
  5. Publish the new recommendation.

Mask Affiliate Links With A Plugin You're Already Using

So there you have it.  In 5 steps you are able to now mask affiliate links without adding more plugins than you need.  I hope that you found this helpful, and please comment with questions.

About the author:

Scott Wyden Kivowitz is the Community & Blog Wrangler at Photocrati, photographer, blogger and educator.

Peter

Peter is a big fan of WordPress and loves to write about WordPress, themes and plugins. You find him here at WP Daily Themes all the time! Cheers!

You may also like...