NOTE: The following has only been tested on version 3.1 of WordPress. It is not my fault if stuff blows up, so follow at your own risk.
I chose to use Shortcode Exec PHP (SEP). I read reviews, checked out the forums, making sure nobody was having major issues or security issues. What SEP does is allow me to create PHP snippets in my WordPress Settings, and call them with short code in a page, post, or widgets. For instance, for my ads I would add
[adsense] where ever I wanted to place my customized ad format.
To do this, you first need to install SEP into your WordPress site, activate it, and then get to writing your snippets. To access the page to add, delete, or edit snippets, go to Settings → Shortcode Exec PHP. On this page you will see a box or boxes for your snippets.
NAME represents the name of the short code that you will call within the brackets in a page, post, or widget. SHORTCODE SNIPPET is the actual PHP markup you will use for this snippet.
So in Google AdSense I have gone ahead and created 3 different ads, each have a different size.
- Blog page and other longer length pages have a text/image skyscraper ad that is 160×600 in size and is in the sidebar.
- Contact page has a text/image box that is 250×250 in size and is in the sidebar.
- Donate page is short, so neither of the 2 above will fit it correctly, so I created a text/image ad that is 468×60, and isn’t in the sidebar.
So, since I am targeting the sidebar widget here, I am just going to look at the ads for my blog and contact pages to do some shortcode for. Like I stated earlier, I gave this shortcode the name
adsense. In the shortcode snippet box I added the following PHP code:
NOTE: your YourAdsUniqueName and google_ad_slot information will be different.
After adding this, I click the Add button, which adds the shortcode and now allows you to edit it, test it, or delete it. In this case testing it won’t be of much good, as it will only return the portion of the add in the
else portion of the
if statement. Next you will want to make sure that both the Enabled and Output echoed boxes are checked.
Next go into your widgets and add a Text widget. In the large post box, all you need to add is
[adsense]. You can wrap this in a
div if you need to do any formatting.
That’s it, now I will have a different ad whether it is on my donate page, a blog page, or a page that is longer.