Tag Archives: WordPress

Placing Adsense After Your First WordPress Post

Google Adsense is a great way to make some money off of your blog, and by placing your code in a couple of key places in your template files, you can have it automatically displayed on all of your blog posts. One thing to keep in mind though is that you can only show 3 ads per page, any more than that and in most browsers an empty space will be left, which is to some extent ok, but in other browsers it can appear as a broken iframe or image. While an empty space isn’t ideal, it can be acceptable, a broken section on your site really isn’t.

It’s for this reason that most people will set up their template to only display Adsense code on the first post shown on each page where multiple posts are displayed. For example on your index page, category pages, tag pages and archive pages.

So to ensure that your Adsense code only displays once you need a way to make sure that when WordPress loops through each post, there is some way for it to figure out whether or not it’s the first post. Joe over at joehayes.org has written a great post about doing this.

Somewhere before the start of the WordPress loop, you need a base way to count. Joe has done this by placing the following code:

<?php $count = 1; ?>

Before the WordPress loop which starts off with:

<?php if (have_posts())

Then inside the content section of the loop which starts off with:

<?php the_content

You need to decide whereabouts you are going to put your Adsense code. Paste it in somewhere, this could be before or after the post content, or after the meta information, or anywhere else that be suit your particular template.

Now, just before the start of your Adsense code you need a way to check the number of posts. We’ll use some PHP to check the $count number that we set earlier.

<?php if ($count == 1) : ?>

This checks to make sure it is still 1. If it is, then your Adsense code will be displayed. If not then it won’t be.

Directly after your Adsense code we then need a way to make sure that the other posts don’t also appear as number 1.

<?php endif; $count++; ?>

This section of PHP tells WordPress to add 1 to the counter. So the next time WordPress runs through the loop, it will be a 2 instead, and it will go 1 higher for each post, so only the first post will appear as 1, thus only the first post will show the Adsense code.

It’s pretty simple but it does the trick very well!

If you wanted to display 2 or 3 ads, one on each of the first 2 or 3 pages, you could simply change the PHP around a little bit.

<?php if ($count <= 3) : ?>

The above snippet for example tells WordPress that if the count number is 3 or lower, than it should display the Adsense code with only 2 minor changes to the original code.

Search Engine Optimisation for a WordPress Client

TerraMedia has recently been contracted to work on fixing up a WordPress website, specifically looking at improving usability and search engine optimisation.

There are a few key things that I will be doing on their website as part of this job.

The first thing I have done is to implement Google Analytics tracking code so that we can begin to get an idea of how people are finding the website. This will track visits while I am working on other sections of the website so that we can get a few weeks worth of results without having to wait idly for them.

There have been reported issues of the navigation not functioning correctly in all browsers, particularly Internet Explorer. As the navigation is vital to accessing website content, it is important to get this working correctly as soon as possible.

Next up I will be updating and modifying the template to help meet both of the criteria by ensuring the markup makes semantic sense, including adding in hierarchical header tags to each page. At the moment, while these are used, each page lacks its own heading, meaning that it is harder for search engines to determine the relevance of individual pages and their content, and users cannot easily see what each page is about.

Once I’ve got the code cleaned up so that is more search engine friendly and the front end more usable, we will start focusing more heavily on getting more traffic to the website from both search engines and other sources, more customers is the primary goal after all!

I will be installing a WordPress plugin called the All In One SEO Pack, which will allow us to specify page titles and meta tags for each page and blog post individually, allowing the keywords and descriptions to be optimised for each page. It also gives better control over the overall meta tags, and tags for archives, categories and so on.

They currently do not have any introductory text on their home page, this means that the root page of their domain name (arguably one of the most important pages of a website from a search perspective) doesn’t really tell search engines anything. It has photos, events, a logo and the navigation. So what we will be doing here is writing up a paragraph or two of highly optimised copy. By this point we should have about a months worth of results from Google Analytics so once this is implemented we will be able to clearly see the difference this text will make and subsequently tweak it as necessary.

To keep the home page fresh and keep the search engines checking it regularly, we will also be having the latest blog post displayed on the home page. As part of this, the client will also begin using WordPress’s blogging functionality to keep the website up to date with the latest news and special offers. They currently do not utilise this functionality, which is a big opportunity to keep their potential customers up to date.

Finally, we will be implementing a sitemap which will be submitted to search engines on a regular basis so that new blog posts and updated pages will be updated in their indexes as soon as possible.

By this point, we should be seeing quite an improvement in search engine rankings and subsequently in website traffic. In order to capitalise on this increased traffic, we will be adding in a static widget that shows the contact details on every page of the website and provides a link to the contact form. This will make it as easy as possible for potential customers to get more information or to make a booking. We will also be making the RSS feed a prominent link on each page to encourage visitors that use an RSS reader to subscribe to the latest updates and specials, and subsequently draw visitors back for potential future and/or repeat sales.

It’s overall a simple but interesting project that will pretty quickly show the difference a well optimised website that is regularyl updated can make. From here, we will start looking at building up links in directories and other relevant websites to continue to improve search rankings and visitor access points.

Template Work

As I am currently working on the new WordPress template for this blog, the design is quite regularly becoming unusable with numerous broken sections as I am testing.

Please feel free to continue browsing the website, and please bear with me in the mean time, once it’s all finished it will look very schmick, just like the template designs I put together previously, but with some new refinements to make it even easier to use, and look even better. To maintain a reasonable level of usability as much as possible, I will be switching back to the “Classic” WordPress theme when I am not working on the template.

Thanks for your patience, have a good one!