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.
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.
From there, scroll down to the new CPT and click the checkbox that says noindex, follow.
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.
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.
- Enter the name of the affiliate program, like you would for any blog post or page.
- Edit the slug for readability. I usually remove hyphens when an affiliate has more than one word, but it’s all user preference.
- Click on the Advanced tab inside fo the WordPres SEO by Yoast box.
- Add the affiliate link under the 301 Redirect section.
- Publish the new recommendation.
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:
- Website Builders Vs Professional Web Designers – What’s the Right Choice - 7 September, 2021
- Top Drag & Drop WordPress Page Builder Plugins - 28 August, 2021
- Dofollow vs Nofollow backlinks: What’s changed and what you need to know - 13 August, 2021