WordPress and Google AdSense

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.

Since I have started using Google AdSense on my blog, I have always used the same size ad on every page. The reason I did this is because of space allotment, and I didn’t know any better at the time. The other day while I was researching AdSense, I was reading about targeting and the different channels. After reading, I created a few different sized ads and tried to figure out how to fit them in to my website. I knew on pages like my blog, where the page was long, I could use a skyscraper ad, but on pages that were smaller, such as as my Contact or Donate pages, I couldn’t use such a large ad. Instead of mucking up my page with Javascript, or better yet my sidebar widgets since that is where my ads are placed, I decided I wanted to go the PHP route, do a single call to the database to get the page name, and go from there. If you have any experience with WordPress, one thing you will notice is you can’t include PHP markup in the body of any pages, posts, or widgets. This is a good thing, as it can potentially become a security risk. Sure there are different plugins you can use that will allow you to use PHP in pages or posts, but I decided on one.

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:

global $post;
if ($post->post_name != 'donate') {
    echo '<script type="text/javascript"><!--';
    echo 'google_ad_client = "ca-pub-0123456789876543210";';
    if ($post->post_name != 'contact') {
        echo '/* YourAdsUniqueName */';
        echo 'google_ad_slot = "0123456789";';
        echo 'google_ad_width = 160;';
        echo 'google_ad_height = 600;';
    } else {
        echo '/* YourAdsUniqueName */';
        echo 'google_ad_slot = "0123456789";';
        echo 'google_ad_width = 250;';
        echo 'google_ad_height = 250;';
    echo '//-->';
    echo '</script>';
    echo '<script type="text/javascript" src="">';
    echo '</script>';

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.

Posted in Development | Tagged , | 1 Response

Account Hackers Have No Mojo

Today while I was writing some code, I got an instant message from a friend of mine I haven’t spoken to in a while. At first I figured it was his dumb self because he can’t spell worth a crap, or is actually pretty dumb in many cases. I shrugged it off and thought nothing of it. After another line or so the next message threw me for a loop. He wanted me to go to some website and trying something. OK, I haven’t talked to you in over a year, and that is the first thing out of your keyboard? I responded with something about porn, and the next response from him is what gave it away. He used ‘plz‘ instead of ‘please‘. Sorry Matt, but you aren’t hip to the Internet chat lingo. After that, I responded letting them know I was on to them, and after a little research I knew it wasn’t Matt at all.

Here is the conversation in its entirety. Thought it was kind of funny, especially since many people would have fallen for this. FYI, the website he wanted me to lookout was revealed by Google of course to be a phishing, virus, and that other crud Windows users have to deal with, website.

Yahoo! Messenger Hacked

Either his password was insanely simple, which I don’t think it was, or he will be calling me within the next couple of days stating something along the lines of, “Can you fix my computer, I think I have a virus?”

UPDATE: After that conversation I filed a report on Yahoo!, just like any good contributor does. I gave them my system information and all of the details letting them know I didn’t have to worry about clicking links. Well it seems they throw that information out and use some USER_AGENT sniffing instead. Boy did they get that all wrong. First off, here is a snippet of what they replied to me with, of course you can tell it is computer generated:

Dear Richard,
Thank you for writing to Yahoo! Messenger.
I understand that you have received an Instant Message or Messages 
containing a suspicious link or links. The links appear to have been 
sent by one or more of your contacts, but were actually sent by a 
malicious third party. Please do not click these links or download the 
associated EXE files. 
Remember, we always recommend that you never click suspicious links or 
download executable files sent from anyone including your contacts. 
Also, keep in mind that we are working to identify the source of the 
issue as well as to take down the sites that are the destination of 
these links.
To remove and prevent further infection, please update your anti-virus 

I told them previously in my report that I was using Linux and had nothing to worry about. Typically this helps with the pre-generated email responses, but in this case it didn’t. Then it went on and detailed the conversation I had with my hacked friend. After that though is what got me, and that was their information about my computer I used to contact them. Here that is:

Machine: Unknown
OS: unknown
Browser: Default Browser 0
Date Originated: Tuesday February 22, 2011 - 13:47:01
Cookies: disabled
AOL: yes

Umm, for one I am not using AOL, and the last I checked, you couldn’t use it with Linux. If their sniffing were correct, it should have looked something like this:

Machine: ShakaDoobie
OS: Linux  (probably either Ubuntu or Kubuntu, as the WordPress sniffers pick this up)
Browser: Default Browser 0  (should say Google Chrome, and it isn't my default browser)
Cookies: enabled
AOL: hell no!

Ahh the fun an excitement I tell you. OK, you can go back to doing whatever you were doing now that I wasted 5 minutes of your time.

Posted in Personal | 1 Response

Linux and GMail Part III – Thunderbird

OK, as you can probably tell now, I have been wasting a lot of time playing with GUI email clients. Why you ask? Simple, I am nuts, like that wasn’t obvious! Like I did in Part I and Part II, I am going to do the same this go round, but with Mozilla Thunderbird instead.

First off, I am using version 3.1.9~hg20110206r5951 from the Ubuntu Mozilla Team Daily Builds PPA. Forgot I added that PPA to check out Firefox, so because of that, I have the version of Thunderbird that I do.

First things first, I like Thunderbird. I will even go as far as saying it is by far the best GUI-based email client available for Linux, and Windows for that matter. It integrates as better as the others, if not better actually, when it comes to tying it in to GMail. My complaints at this time are small, damn small. They are:

  • Unsubscribing from an IMAP folder does not hide that folder, you can still see it in the list, annoying
  • I don’t use local folders, so I had to download Mail Tweak just to hide it. Mail Tweak has about 50 or so other tweaks built into it, but I am only using one of the tweaks
  • You have to try a few shitty extensions until you find the right one

I have 2 GMail accounts set up, and there are different folder views you can use. I was using the Unified Folders view, which is a really great idea, one I haven’t seen on any other client out there. So I have 2 accounts, and they both have an Inbox, this will show only 1 inbox with both of them combined, and when you expand that inbox, you can then access each inbox individually. This saves space when you have a ton of folders in view. Another thing I like is the support of IMAP IDLE which allows damn near real-time communications between GMail and Thunderbird. You can kind of think of it as the PUSH Technology deployed in mobile devices these days. It is funny. An email will show up both on my Android and Thunderbird before it does in the GMail web client. When I get a new email in my inbox, a message pops up, and at the same time my phone makes a noise, and about 15 to 30 seconds later, the message shows up in my GMail web client. Also, it uses its own message indicator and not the Ubuntu or Kubuntu indicator. I kind of prefer the Thunderbird one because it is more out of the way for me. To be honest, I absolutely hate the indicators in Ubuntu and Kubuntu, but that is my personal preference, I just have a different work flow than those who like them.


It doesn’t look to bad in KDE. Of course it doesn’t fit in look wise, but that is easily overlooked when it comes to functionality, speed, and usability. I have installed the Zindus extension which syncs my calendar and contacts with Google’s calendar and contacts. It does this better than any other extension out there, so don’t waste your time trying this or that, just get Zindus, enter your username and password, and in seconds you are up and running. Thanks to Timothy Richardson for leaving a comment telling me about Zindus. As it stands, I don’t think I am missing anything from any of the other clients that I wish was here. Well maybe a social tab with sex built in like Zimbra Desktop had, out of the box I might add.

So, are you a Thunderbird user? Am I missing anything? Any extension that is a must have? Any tips or tricks I need to know? Speak up in the comments and let me know.

NOTE: Inbox zero!!!

Posted in Application, Linux | 18 Responses
  • Archives