How to Add the Google Analytics Tracking Code to Your WordPress Blog

12 Aug

Google Analytics is a powerful tracking tool. With it you can track visitors and retrieve extremely useful data of your visitors behaviour.

But how do you add the Google tracking code to WordPress? I aim to give you an answer in this tutorial.

Get the Tracking Code

First of all you have to retrieve the Google Analytics tracking code. To do this you have to login to your Google Analytics account. Then click on the profile to which you have added your web site. If you have already created a new profile for the website then click on Edit at the right side. On the next page click on Check Status. There at the bottom you should be able to find the tracking code.

If you haven’t added the blog you want to track to Google Analytics then go ahead and click on Add New Profile.  This will lead you to a new page where you have to enter the domain of your website. Enter it and leave the other options as they are and hit Finish. The final page will appear with the tracking code. The code should look like this:

<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-xxxxxxx']);
_gaq.push(['_trackPageview']);

(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();

</script>

Now once you have the tracking code just copy it. Now go to your WordPress blog and log in. Once you are in your WordPress dashboard click on Appearance -> Editor. When the new page shows up click on the header.php file on the right hand side. This will let you edit the header of your WordPress theme. Simply scroll down to the </head> HTML tag. Then paste the code, which you previously copied, above the </head> tag and click on Update File.

That’s it and Analytics should be able to track your visitors.

Speed up WordPress by Putting CSS Files in the Header

6 Aug

All CSS files that are used on a web site should be included in the header section or the header.php file for that matter. Combined with flushing early, this will increase the speed of your web site since all the CSS files are included in the header and can be downloaded right after flushing.

Also putting CSS files in the header means that the content can be rendered progressively, i.e. it can be presented fast to the visitor. This is especially important for people with a slow Internet connection as loading the CSS sheets will indicate progress to the visitors.

In order to do this go and log into your WordPress dashboard. There you click on Appearance -> Editor. Now click on the header.php file on the right hand side. Now search for CSS links, they always look like the one below:

<link href="http://downtownwordpress.com/wp-content/themes/bueno/styles/default.css" <strong>rel="stylesheet"</strong> type="text/css" />

Once you have located them simply move them before all of the Javascript code. Javascript code looks like the code below:

<script type="text/javascript">

That should ultimately make your blog a little bit faster. There are also several others tricks you can use to speed up WordPress.

Speed Up Your WordPress Blog by Moving Your Javascript Files to the Bottom

6 Jul

Speeding up your WordPress blog is crucial especially if you have lots of new visitors. If your blog then loads slow you have a high chance of losing them simply because of your website speed. With WordPress there are lots of things you can do to simply speed up your blog.

One of these things is to move your Javascript files to the bottom of the page.

Javascript is used on most web sites these days. Usually Javascript is not used to render content or anything of real importance. Therefore it makes sense to move it into the footer (or footer.php). Another issue is that usually a web browser can download two files in parallel, with Javascript this is different:

While a script is downloading, however, the browser won’t start any other downloads, even on different hostnames.

This makes it necessary to move all the Javascript files to the bottom of your web site because otherwise Javascript will slow down your WordPress blog. All you really need to do is to go to your WordPress dashboard and head to Appearance -> Editor. Then simply click on header.php. There copy all the Javascript code, if you don’t know what the Javascript code it’s everything beginning with <script like this line below:

<script type='text/javascript' src='http://example.com/wp-includes/js/jquery/jquery.js?ver=1.4.2'></script>

You need to find all the lines beginning with <script … and then stop until you see </script> tag and copy it. You need to do that with every script line in your WordPress header.php file. While copying the code simply open up a new browser window that has the WordPress editor open and lets you change the code of your footer. Then paste the code before the </body> tag.

Once you have done this with all of the scripts be sure to press Save. You should now have a faster WordPress blog.

How to Track Events with Google Analytics on Your WordPress Blog

5 Jul

There are lots of people using WordPress these days. The default WordPress stats plugin is usually not enough to grasp enough information about your blog visitor. That’s why so many people turn to Google Analytics to get some more detailed visitor information.

In this article I want to cover how you can integrate events to for example track click on affiliate links and so forth.

First of all you need to download an additional script that you need to place on your WordPress blog. This script is called gaddons and is there to track outbound links and downloads. Simply download the script and upload it to wp-content/themes/the-theme-you-have-activated/.

Once you have done that go to your WordPress dashboard and go to Appearance -> Editor. There click on footer.php or header.php depending on where you have put your Google Analytics code.

Then simply add

<script src="gaAddons.js" type="text/javascript"></script>

below your Google Analytics code. So it should look something like this

<script type="text/javascript">
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
</script>
<script type="text/javascript">
try {
var pageTracker = _gat._getTracker("UA-xxxxxxx-x");
pageTracker._trackPageview();
} catch(err) {}</script>
<script src="gaAddons.js" type="text/javascript"></script>

Now all you need to do is to add some code to the links that you want to track. Let’s say you have a simple link pointing to an article about speeding up WordPress like the one below

<a href="http://andbreak.com/articles/guide-speed-wordpress/">Speeding Up WordPress</a>

Now in order to track the event of someone clicking on that link you simply change the HTML and include the onClick attribute:

<a  href="http://andbreak.com/articles/guide-speed-wordpress/" onClick="pageTracker._trackEvent('OutboundLink', 'Speeding up WordPress');">Speeding  Up WordPress</a>

Now whenever someone clicks on this link Google Analytics will record it. Once you have set up this code you will have to wait at least a day before you will start seeing results. If you want to see the Event Tracking Overview go to Google Analytics and log in. Then click on the website on which you have set up event tracking. Once the new page appears click on Content -> Event Tracking and you will see the result on whether people have clicked on your links.

If you want to learn more about event tracking then be sure to visit Google’s Analytics guide. Remember though that depending on the version of your Google Analytics code the code from below might differ.

How to Verify Your Google Webmaster Blog Submission in WordPress

25 Jun

Most of the bloggers today rely heavily on Google products to support their blogs. One of these services is the Google Webmaster tool. This allows you to submit your website to it and let’s you control different things with it, such as the crawling rate or the preferred URL etc.

But how do you actually verify your WordPress blog for Webmaster Central?

There are several methods that Google offers you but the easiest one is to simply include a meta tag within the header of your blog. That’s also the method I am going to cover here.

Alright now let’s get started. Visit the Google Webmaster Tools page and sign in. Once you are logged in simply click on Add a site… and enter the address of your website. Then hit Continue and on the new page select Meta Tag from the dropdown menu.

Verify your website

Simply copy and paste the code that is shown in the middle of the page

Now a code will show up below which is the code that you are going to have to add to your WordPress blog header. Simply copy the code.

Now go to your WordPress dashboard and click on Appearance -> Editor. On the right side select the header.php file. Now simply paste in the code you were given between the <head> and </head> HTML tag, as shown below.

<head>
...
<meta  name="google-site-verification"  content="uniquecodestring" />
...
</head>

The last step is to simply click on Verify. If Google can’t verify your site right away it might be because you are caching all of your pages on your WordPress blog. Then simply try to verify it on the next day.

How to Stop Comment Spam on Your WordPress Blog

20 Jun

WordPress is a great piece of software for blogs. Most people nowadays rely on it to power their blogs. But there is one problem not even WordPress can master.

And that is spam. Even though you might not get that much spam it’s pretty annoying to deal with. Of course the default Akismet plugin is a way of dealing with spam. But even with it you still get some decent amount of spam.

Now how can you stop even more spam comments?

Again there are several ways you can approach this but plugins are the easiest way to deal with it. And there are many plugins available that are supposed to be able to stop spam comments but the most effective one for me has been Bad Behavior.

Install the Anti Spam Plugin

Add a New WordPress Plugin

Click on Add New

To install the anti spam plugin simply visit your WordPress dashboard. Click on Plugins -> Add New. Then simply enter Bad Behavior into the search box and click on Search Plugins. From the list you see go to the Bad Behavior plugin, it should be the first one on the list, and select Install Now.

A popup should come up asking you whether you want to install the plugin, click on Yes. A new page should now load which will automatically update. Once it says that the plugin is installed then click on Activate Plugin.

Once it has been activated then go to your WordPress dashboard and click on Settings -> Bad Behavior. Now you can simply customize your settings.

The one thing I would change though is to switch off the Display statistics in blog footer checkbox since I find it intrusive. Otherwise I would keep the settings the way they are. Just remember to click on Update when you want the changes to take effect.

Now your WordPress blog should be much better defended from comment spam.

How to Create a Sitemap on Your WordPress Blog

20 Jun

Sitemaps are important these days since search engine will index your website that much faster and much more complete once you have a sitemap on it.

So how do you create a sitemap for your WordPress blog? What do you need to do in order to create a sitemap?

The easiest and also most comfortable way of creating a sitemap for your blog is to simply install a plugin that will do the whole process for you. The plugin I like to use is Google XML Sitemaps since it’s a great plugin.

Install the Sitemap Plugin

Add New Plugin

Click on Add New

To install it simply visit your WordPress dashboard. Click on Plugins -> Add New. Then simply enter Google XML Sitemaps into the search box and click on Search Plugins. From the list you see go to the Google XML Sitemaps plugin, it should be the first one on the list, and select Install Now.

A popup should come up asking you whether you want to install the plugin, click on Yes. A new page should now load which will automatically update. Once it says that the plugin is installed then click on Activate Plugin.

Once it has been activated then go to your WordPress dashboard and click on Settings -> XML-Sitemap. Now you can simply customize your sitemap settings, the standard settings are fine though.

So now you just created a sitemap for your WordPress blog.

How to Remove the WordPress Short Link from the Blog Header

9 Jun

If you have recently taken a look at your blog’s source code you might have noticed that there is a link tag containing a short link code.

<link rel="shortlink" href="http://wp.me/WTSy" />

The link should look somewhat like the one above.

All WordPress does through this link is to add a short link that you could use for social media services like Twitter among other things.

If you want to get rid of this code then you should go to your WordPress dashboard. Then go to Appearance -> Editor and select the functions.php file. Then simply enter the code below within the PHP tags.

remove_action("wp_head", "shortlink_wp_head");

Click on Update and then the next time the page loads it should be gone. Notice that sometimes it may take a while for changes to actually show up due to caching. In that case you might want to check again later.

How to Remove the WLWManifest Link in Your WordPress Header

9 Jun

If you have taken a look at your WordPress blog’s source code then you will indefinitely notice that there is a link tag added to it.

<link rel=”wlwmanifest” type=”application/wlwmanifest+xml”  href="http://www.domain.com/wp-includes/wlwmanifest.xml” />

It should be like the one below. But what does this link do? Is it helpful at all?

The wlwmanifest link in the WordPress header  is there to help Windows Live Writer to download and discover the manifest file, i.e. wlwmanifest.xml.
The link is simply added to enable support for Windows Live Writer. If you aren’t using Windows Live Writer then you don’t need this line of HTML code in your header.

To get rid of this, all you need to do is to go to your WordPress dashboard. There you should click on Appearance -> Editor. Finally within the editor select the functions.php file. Now simply add the code below within the PHP tags.

remove_action("wp_head", "wlwmanifest_link");

There is also a WordPress Plugin available to do this for you but this is really not necessary since all you need to do is add the above code to the functions.php file.

How to Delete the Default WordPress Administrator Account

6 Jun

Securing WordPress is a big issue these days especially since WordPress has become extremely popular. In this article I want to cover one tip as to how you can delete the default WordPress admin account.

By the deleting the admin account malicious users do not get to know your user name so easily. As every WordPress installation comes with a default admin account, hackers will have an easier time breaking into your account if you don’t change your user name.

You cannot delete your administrator account right away in your WordPress dashboard if you do not have a new admin account, so follow these steps:

  1. Create a new administrator account
  2. Log out of WordPress
  3. Log back in with the new admin account and password
  4. Delete the old account administrator account

You can also delete or change the administrator account by using phpMyAdmin but the procedure mentioned above is a lot easier I believe.