My First WordPress Shortcode

Up until early this morning, I’ve resisted using shortcodes in my WordPress blogs.

But this morning I built my very own first custom shortcode. Sure, it’s simple and short and probably painfully plain. So?

I plunked it in my active theme’s functions.php file and it works great! I know that by putting it there I’m limiting its application to my current theme. If I change themes, I’ll have to add the code to that theme’s functions.php.

That means that my shortcode is a prime textbook candidate for inclusion in a custom functions plugin instead. Then it would work from theme to theme. Maybe later I’ll do that.

But never mind all that. I made my shortcode by putting these four lines of code in my functions.php file:

function dlink(){
	return '<a href="http://www.amazon.com/gp/product/158134435X?ie=UTF8&tag=anabaptistbookst&linkCode=as2&camp=1789&creative=390957&creativeASIN=158134435X">Daily Light on the Daily Path</a><img src="http://www.assoc-amazon.com/e/ir?t=anabaptistbookst&l=as2&o=1&a=158134435X" width="1" height="1" border="0" alt="" style="border:none !important; margin:0px !important;" />';
}
add_shortcode('DLlink', 'dlink');

All I had to do to include it in my post was this: [DLlink].

Doing that generates a link to Daily Light on the Daily Path that is embedded with my Amazon affiliate stuff, like this: Daily Light on the Daily Path.

Very slick! And I don’t need to get all that affiliate code every time I want to link to that book. I just have to put [DLlink] wherever I want that link to appear.

To see the results live…and for hope in the middle of trouble…go to The Day of Trouble.

Comment? Sure!

Above all, love God!
%d bloggers like this: