You know it’s important to have an SEO-friendly content management system, and WordPress is my favorite CMS for most small business websites. Recently I’ve been using the Thesis theme for WordPress for most web design projects, and I’d be hard-pressed to launch a new site with anything else. In fact, this site is built on Thesis.
Thesis is well-optimized out-of-the-box and you can easily customize your blog design with just a few clicks of the mouse. It’s a no-brainer purchase if you’re looking to redesign or start a new website. That being said, there are times when you want to make some customizations outside the scope of the Thesis design interface. In these cases, you’ll need to use the custom_functions.php file. Sounds scary, I know, but it’s not so bad once you’ve used it a few times.
One function not provided out-of-the-box (yet) is easy integration of your PPC conversion code. But this can be easily fixed using a custom function.
Here’s an example. Let’s say I want to track how many people sign up for my free Small Business SEO lessons via AdWords. I would put the following code in my custom_functions.php file:
function insert_tracking_code() { ?>
<?php if (is_page('Thank You for Subscribing')) { ?>
<!-- Google Code for SEO-O Small Biz Lessons Conversion Page -->
<script type="text/javascript">
<!--
var google_conversion_id = xxxxxxxxxx;
var google_conversion_language = "en";
var google_conversion_format = "2";
var google_conversion_color = "ffffff";
var google_conversion_label = "yyyyyyyyyyyyyyyyyyyy";
var google_conversion_value = 0;
//-->
</script>
<script type="text/javascript" src="http://www.googleadservices.com/pagead/conversion.js">
</script>
<noscript>
<div style="display:inline;">
<img height="1" width="1" style="border-style:none;" alt="" src="http://www.googleadservices.com/pagead/conversion/xxxxxxxxxx/?label=yyyyyyyyyyyyyyyyyyyy&guid=ON&script=0"/>
</div>
</noscript>
<?php } ?>
<?php }
add_action('thesis_hook_after_html', 'insert_tracking_code');
So let’s break this down into a generic code snippet you can use on your own website:
function insert_tracking_code() { ?>
<?php if (is_page('The Name of Your Conversion Page')) { ?>
<!-- Insert Google Code for Your Website Conversion Page Here -->
<?php } ?>
<?php }
add_action('thesis_hook_after_html', 'insert_tracking_code');
First, we defined what we wanted to do by making a function called insert_tracking_code. We said that if someone was on a page called [whatever you named your conversion page], then go ahead and execute the Google AdWords conversion code (you could also throw in Yahoo! and MSN conversion codes if you’d like).
Next, we used add_action to tell our server where to execute that function
- The first part of the
add_actiondirective is the where (thesis_hook_after_htmlis a Thesis-specific hook that tells the server to place the code just before the</body>) - The second part of
add_actionis the what – execute theinsert_tracking_codefunction, which we just defined above
So there you have it. Now you can easily implement conversion code on your site without hacking the WordPress core.

{ 1 trackback }
{ 5 comments… read them below or add one }
Hello, I have added the code into the custom_functions.php to track conversions on the Transaction Results page which is the page the customer returns to after paying with Paypal. I purchased a test product and no conversion has shown up in Adwords.
When I copied and pasted the code from adwords and added the additional hooks it all went on one line in custom_functions.php – I wondered why this happened and if this could be the problem.
Any help would be appreciated.
Have you any ideas as to what might be wrong.
Still attemptin to find out why conversion tracking is not working. My tracking page is Transaction Results although the full address is domain/product-page/transaction-results – Do I need to put product-page/transaction-results in the page name?
Hi Jenny,
Looking at the source code of http://www.readscreations.co.uk/products-page/transaction-results/, I do see the conversion tracking code, so it appears the custom function worked properly.
When you did the test order, did you click through from an AdWords ad?
Remember, this code will only count conversions for AdWords PPC advertising. You would also need additional code for Yahoo and MSN PPC if you’re advertising on those networks as well.
PS – Happy New Year!
Hi, John,
Will you be so kind to make a screencast for this?
It may seem super easy for you but it’s all gibberish to a noob. =)
All I want is to add the tracking code to my converting page. And your insight is the closest to the solution I am looking for.
Your assistance will be much appreciated.
Thanks.
Lux
Hi Lux,
I probably won’t have a chance to make a screencast any time soon, but I think it’s a great idea – I’ll keep it in mind for a future post. In the meantime, let me see if I can make the process a bit easier to understand (I probably left out a few important steps above).