You may have noticed I use a lot of Amazon affiliate links in my text to try and monetize my sad little ramblings on this blog. Up until this point, I was using EasyAzon to manage them. This worked okay, but I didn’t like the complexity of the shortcode and link, or the dependence on Amazon Web Services. I modified the source to bypass these problems, but every time they updated the plugin, they came back.

So, I learned a tiny bit about writing WordPress plugins to create this simple little gem.

Now, all I have to do is make a little tag in the following form, where “ASIN” is the Amazon product ID, and the plugin will generate the link for me.

[amazon asin="ASIN"]Link text here[/amazon]


To make this work, create a folder in /wp-content/plugins named anything you want, I chose amazon-shortcode. Make a file inside of that folder, I named it amazon-shortcode.php. Paste the following code into it, and replace “walsranfest08-20” with your own Amazon affiliate ID.

* Plugin Name: Amazon Shortcode
* Plugin Uri:
* Description: Turn [amazon] shortcode tags into Amazon affiliate links
* Version 0.0.1
* Author: Walter Heitman
* Author URI:
* License: Egoware

function transform_amazon_to_link($atts, $content = "Amazon Link") {
	$azaffiliate = 'walsranfes08-20';
	return '<a href="' . $atts['asin'] . '/?tag=' . $azaffiliate .  '">' . $content . '</a>';
add_shortcode('amazon', 'transform_amazon_to_link');


Need I ever change my affiliate ID or the link style, I only need to modify this file.

Hope you find it useful, if not for link generation, then perhaps as a simple example from which to learn to make your own plugins.