How to Hack your Template

This post is of special interest to authors (or people who run an online affiliate bookstore, I suppose, but you can get widgets from Amazon for that). That said, I’m going to tell you what I did recently and how to do it yourself because I’m feeling helpful. If you already know all about coding and php and css, then you can click away because this will be boring for you.

Authors: if you’re like me, you probably don’t want a website that sucks up all your time. Which means you don’t want to spend your days coding. You want to be writing. For that reason, I moved away from an HTML site that I had to update manually in .txt files and then move them to my directory via ftp. That took forever, and I wasn’t quite good enough at it to make it time-efficient. So I switched to WordPress, which is much easier. It’s easier to upload, add pages, and what-have-you. But my chief complaint is this: when I sell a new book, I need purchase links eventually. And I hate tracking down different links from different stores, pasting it all in. It’s time-consuming.

Which brings me to the awesome Courtney Milan, who came up with this sweet script for PHP websites. Using this, all you have to do is paste one line of code into your website, with correct ISBN-13 (no dashes) and it automatically generates a fuckton of buy links. It’s simple, lovely, and painless. Unfortunately, if you use a WordPress site, it requires some hacking to make it work.

That said, I did it. And if I can, you can. If you want to. Because I have no background in this. My degree is in English Literature with a minor in Humanities. I didn’t touch a computer until I was in college, and I didn’t own one until I was 25. So here we go: my how-to hack your template.

First, you need to log in to your WordPress dashboard. Once you’re in there, click on plug-ins. After that new screen loads, click on Add New at the top. This will take you to a search page. Type “Executable PHP” in the box, and choose Exec-PHP. In my searches, it’s number two. Click “install now.” Let that run, and once it says it’s done / successful, activate it. Let that process finish. Now your WordPress site is ready for that magic one line of code that will make your buy links easier. (If you don’t have a version of WP that lets you auto-install plug-ins, I’m not walking you through the manual process. Update your WP!)

The next thing you need to do is add the script to your template. Don’t worry. It’s easy. Use my script here, as it’s been optimized by Moira Rogers for WordPress. (I tested it on three different WP sites of mine, Ann, Ava & Ellen, and it slid in neatly to three different templates. I expect it will work well on any WP site.) It’s similar to Courtney’s with a few tweaks to make it display neatly on your WP site. Copy this now, paste it into a .txt file, save, and put it on your desktop where you can find it later.

Your next step is to click on Appearance to the left. Click on editor at the bottom of that submenu. That will bring up the stylesheet. Don’t touch that unless you really know what you’re doing. Instead, look to the right, and find where it says Header. Click on that. Put your cursor at the very top of the screen, above everything. It should say DOCTYPE or something like that. Hit return a few times to make some space. Open up the PHP script you downloaded earlier. Copy everything in the file, exactly as it is. Then paste it in the space you made in your header file. Then hit update file on the bottom. It should say it has saved successfully.

And that’s all. Now you just need to edit your individual pages with your magic line of code. (That means copying it from here, pasting it where you want your links to go, and deleting anything you had on the page before for purchasing.) Make sure you replace my ISBN-13 for Blue Diablo, shown in the code, for your book’s correct ISBN, minus the dash. Do that, and you will be golden.

That’s it! And it will generate links, like so. No more updating links. No more bothersome pasting of multiple bookstore links. Yay for efficiency!