Posts Tagged ‘blogging’

Ad Injection plugin for WordPress

Monday, December 6th, 2010

Ad Injection is a free WordPress plugin that injects any kind of advert (e.g. Google AdSense, Amazon Associates, ClickBank, TradeDoubler, etc) into the existing content of your WordPress posts and pages. You can control the number of adverts based on the post length, and it can restrict who sees adverts by post age, visitor referrer and IP address. Adverts can be configured in the post (random, top, and bottom positions) or in any widget/sidebar area. There's support for A:B split testing / ad rotation.

ad injection plugin for wordpress 1 450

PayPal – The safer, easier way to pay online.


Download Ad Injection plugin for WordPress for free from this link. Or just search for Ad Injection from your WordPress install and WordPress will automatically install it for you.


Automatic advert injection

The ads can be injected into existing posts without requiring any modification of the post. The injection can be done randomly between paragraphs, and there is an option to always inject the first advert at a specified paragraph (e.g. the first or second). Randomly positioning the adverts helps to reduce 'ad blindness'. Two additional adverts can be defined for the top and bottom of the content. Widget adverts can be defined as well for your sidebars.

ad injection plugin for wordpress 3 450

Widget support

Widgets can be added to your sidebars, or other widget areas on any pages. The same ad display restrictions that you setup for your other ads will also apply to the widgets.

Ad rotation / split testing

You can define multiple adverts for the same ad space which are rotated according to the ratios you define. Works with random, top, bottom and sidget/sidebar ads.

Ad quantity by post length

The number of adverts can be set based on the length of the post. It is a good idea for longer posts to have more adverts than shorter posts for example. Adverts can also be turned off for very short posts.

ad injection plugin for wordpress 4 450

Ads on old posts only

Adverts can be restricted to posts that are more than a defined numbers of days old. This prevents your regular visitors from having to see your ads.

Category, tag and post type filters

You can configure the adverts to only appear on specific categories, tags, or post types, or block the adverts from specific categories, tags or post types.

Search engines only (dynamic feature)

You can specify that ads should only be shown to search engine visitors (or from any other referring websites) so that your regular visitors (who are unlikely to click your ads) get a better experience of your site. You can define which search engines or any other referring sites see your adverts. A visitor who enters the site by a search engine will see ads for the next hour.

Block ads from IP addresses (dynamic feature)

IP addresses of people who shouldn't see your ads can be defined. These could be the IP addresses of your friends, family, or even yourself.

ad injection plugin for wordpress 2 450

Not tied to any ad provider

The advert code can be copied and pasted directly from your ad provider (Google AdSense, adBrite, ClickBank, etc) which will help you to comply with any terms of service (TOS) that state their ad code may not be modified.

Flexible ad positioning

Easy positioning options are provided for left, right, center, float left, and float right. Extra spacing can be set above and below the ad. Or if that isn't flexible enough, you can write your own positioning code using HTML and CSS.

You can specify a specific paragraph for random ads to start from, or if you need per-post control of the random adverts you can insert tags into the post source to say where the adverts should start and end.

ad injection plugin for wordpress 5 450

Inject PHP and JavaScript

As the plugin will inject whatever content you like into the page you can write your own ad rotation or a/b split testing code for the ads you inject. PHP code can be automatically executed.

Full documentation is available on the WordPress Ad Injection page.

If you do get any errors please use the 'Report a bug or give feedback' link on the plugin to send me the error details.

Proof that Alexa rankings can be very inaccurate for small websites

Thursday, July 29th, 2010

Here is a comparison of the actual viewing figures for this site (as recorded in Google Analytics), against the values that Alexa reports.

Alexa vs Google Analytics page views

This is a fairly small blog, getting 600-800 page views per day. If you too have a website which is of a similar size you might be interested in just how wrong Alexa’s statistics can be. Here is Alexa’s estimate as to how the number of page views I’m getting has changed in the last three months (snapshots all taken on the 15th July).

alexa page views

Looks pretty amazing right? A 2420% increase in page views in three months. But all is not as it seems. Here are my actual page views from Google Analytics (same three month period). You can see the actual figures show a very gentle increase in page views.

google page views

Alexa operates by sampling data from the people who have installed its toolbar, or who have installed (or had installed for them!) some other piece of software which sends data back to Alexa.

The percentage of internet users who have Alexa software on their computers is small so the data is subject to anomalies, especially as the website gets smaller. A large website such as Facebook or MySpace probably gets ok results from Alexa as there will be thousands of people browsing these sitse who have the toolbar installed. But the smaller the site, the bigger the potential for the results reported by Alexa to be out of sync with the actual results.

Alexa vs Google Analytics page views per person

So why the huge reality vs Alexa distortion for my site? I’ll come to that later. Next let’s looks at another graph. This is how Alexa thinks my page views per person is doing.

alexa page views per user

Pretty impressive! The page views per person has gone from 1-2 all the way up to 30 pages viewed per user. If that were accurate it would mean that people really love reading what I write! But unfortunately my blog isn’t quite that engaging. Here are the real figures. Each of my visitors looks at about 1.3 pages. That figure has remained fairly flat over the last three months.

google page views per user

Alexa vs Google Analytics visitors per country

Here is my final set of figures. This is where Alexa thinks most of my visitors are coming from.

alexa percent traffic by country

You can see from their figures that they think most (74%) of my visitors are in Japan. It is vaguely plausible as I do have quite a few Japan related postings on this site. However it isn’t accurate. Here are the real figures.

google percent of traffic

You can see that only 1.4% of my visitors are in Japan. This largest percentage of viewers is actually from the UK (44%), but Alexa only believes that 4.5% of my viewers come from the UK.

So why is Alexa so badly wrong?

What is causing Alexa to be so badly out of sync from reality? I am pretty sure I’ve worked out the reason. I believe that the massive inaccuracies are the result of a single person. Me.

Not on purpose, I did it entirely accidentally. But it is interesting that one person could cause the perceived page views of a 600-800 page per day blog to jump 2420% in three months. It is also interesting that one single person could accidentally cause the Alexa traffic rank to jump from about 600,000 to 200,000 in such a short time. And it is impressive that one single person could cause Alexa to think that 74% of visitors are from Japan when in fact only 1.4% of them are. Also that I could cause the average page views per person to go from 1-2, all the way up to 30ish.

How did I (accidentally) cause Alexa’s figures to be so wrong?

There is one main cause of this massive misreporting of figures. I installed the Quirk SearchStatus extension for Firefox. This extension add some small items to your status bar at the bottom of the browser. They can show the Google PageRank for the web page you are currently on, and they can show the Alexa traffic rank for the website you are on.

But the extension doesn’t silently report the statistics. It actually affects the Alexa traffic rank statistics. As you are browsing where you go will now be recorded by Alexa.

In my case I spend a lot of time on my own blog. It is WordPress blog so I need to access it to put up new posts, edit posts, check posts, moderate comments, and install/configure new/updated plugins. In a typical day this could easily generate another 30-50 page views of my blog that are reported to Alexa.

It would seem that although all my page views are coming from the same IP address, they are still able to make Alexa think that my blog is seeing a huge surge in traffic.

The timing is right too. The time I installed the plugin matches the time I started seeing this huge surge in Alexa rankings. And that’s not all. A short while after installing the plugin I headed to Takamatsu in Japan and continued working on my blog from there.

The fact that I had moved from the UK to Japan caused caused Alexa to think that most of my visitors were now coming from Japan.

Almost all of this was caused by me accessing my WordPress blog in a normal way whilst having this Firefox extension installed.

What it shows is how inaccurate the numbers can be for small sites such as mine. The number of people whose browsers report statistics to Alexa is sufficiently small that a single person can seriously skew the data.

So look at Alexa’s statistics if you really want to. But remember that unless you are looking at the stats for a huge site, they may well be way off the mark.

Notes on upgrading to WordPress 3.0 on 1and1

Tuesday, June 22nd, 2010

Normally I’d wait until at least the x.01 release of a new WordPress before upgrading. But this time I wanted to try the new WordPress soon after the final 3.0 version was out. I still waited a few days before installing it to let other people discover and fix any initial problems.

Problems and fixes

My wait paid off as a number of people who were using the same hosting company as me (1and1) found that the upgrade was failing with a ‘Fatal error: Allowed memory size of xxxxxxxx bytes exhausted’.

The fix for this problem is very simple – increase the allowed memory size, either by adding a php.ini , updating the wp-config.php, or for those who could wait a few days for an easier fix, by installing the Memory Bump plugin.

I installed Memory Bump, and went through all my usual WordPress backup steps, before attempting the install.

I pressed the Upgrade button, WordPress did something for about a minute and then I got this error message:

Downloading update from
Download failed.: Operation timed out after 60 seconds with 1023460
bytes received
Installation Failed

Not to panic though, this error is just saying that WordPress didn’t manage to download the new install package before its 60 second timeout. I pressed the button again, and this time it worked!

Downloading update from
Unpacking the update.
Verifying the unpacked files…
Installing the latest version…
Upgrading database…
WordPress upgraded successfully

New themes

The reason I wanted to upgrade as soon as possible was so that I could give reviewmylife a new theme. The old Kubrick theme was getting a bit old.

old reviewmylife blog

After a bit of searching and experimenting I found the News Magazine Theme 640 which I have now switched to.

new reviewmylife blog

One word of advice if you are switching themes – if you swap to a new one, and then back to the previous you might find that all your widgets have been set to inactive. You’ll have to re-add them again.

A second piece of advice is to keep any caching plugin you might have disabled whilst you play about with new themes and theme settings. This will make sure that you always see the latest generated pages, and not older cached ones. Don’t forget to turn the caching back on afterwards!

A later error

Whilst modifying one of my plugins I got this error on trying to activate it.

The plugin generated 3 characters of unexpected output during
activation. If you notice “headers already sent” messages,
problems with syndication feeds or other issues, try deactivating
or removing this plugin.

There are many possible causes, but in my case the problem was down to having opened the .php in Notepad and accidently saving it as UTF-8 instead of ANSI. I re-saved it as ANSI and it worked again.

Renaming table prefix on WordPress 2.9

Wednesday, May 19th, 2010

I wanted to rename the table prefix for this blog before upgrading to WordPress 3.0. I knew about the WordPress Table Prefix Rename Plugin which claimed to work for WordPress 2.x, but I couldn’t find anyone saying they had tried it specifically on WordPress 2.9.

wordpress table rename plugin

The only thing to do was to try it myself. As stated in the documentation this plugin doesn’t actually rename the tables, it copies the tables, and gives the copies your chosen prefix. It also modifies a few entries in the new tables which refer to the tables by name. Then it modifies the prefix entry in wp-config.php.

Before using it I looked through the PHP source code to make sure I was happy with what it was going to do. And of course I made full backups of my tables just in case it all went wrong.

I disabled the WP Super Cache plugin, and deleted the cache, to make sure that after the rename I could see the actual generated blog pages, rather than pages that had previously been cached by WP Super Cache.

I also opened the phpMyAdmin control panel that my web host (1and1) uses for managing the MySQL databases.

After installing and activating the plugin I went to its setting page, typed in my chosen table prefix, and pressed ‘Generate New Tables’. After 2-3 seconds it was done. I made a copy of the SQL statements that had been used (they get displayed on screen) for reference just in case I needed them later.

Then I pressed ‘Change $table_prefix’ button. This only took a second.

To check that everything had worked I logged out of WordPress and back in. I checked a few pages on the blog as well. And I checked wp-config.php using my FTP program to make sure it had been modified. It had all worked!

Using phpMyAdmin I checked that the new tables were the same size as the old ones (taking into account any overhead in the original tables).

I’d recommend you keep the old tables until you are sure that the new ones are working fine. Wait a few weeks – or even longer before deleting them if you have space. They don’t do any harm, and act as an extra backup of your data.

Table renaming tips

  • Read the plugin source so you know what it is going to do.
  • Backup your database tables, and verify that the backup is good.
  • Set aside enough time to restore your blog from backups in case it all goes wrong.
  • Keep your original tables if you have the space. More backups are good.

What I’ve learnt after 100 blog posts

Saturday, March 27th, 2010

Today marks a significant milestone for this blog. After two and a half years I have reached my 100th post! I thought this would be a good moment to look back at what I’ve learnt from writing a hobby blog.

mini keyboard and cadbury sweets

Why I created this blog

I’ve been a hobbyist website builder for about 13 years now. I’ve created a mixture of technical and personal topics. These have always been static websites where each page was created individually, either using a HTML editor such as HoTMetaL, or by using hand written HTML templates. Each website tended to stick to a particular topic, and some of them have done moderately well, getting many hundreds of visitors each day.

I had an ideal for another website where I could write about miscellaneous topics that didn’t fit anywhere else. I registered a new domain name with 1and1, created some static HTML templates, and started writing some content. I soon gave up as I found that I was spending too much time on the mechanics of creating each page, rather than on the more creative writing aspect. I abandoned the idea for a year, and didn’t think much more of it.

Starting up

I began reading about blogs, and self hosted blogging platform like WordPress. I thought that my miscellaneous topic website might work if I used something like WordPress as the content management system.

At the time I was on a very basic web hosting package with 1and1 and I had to upgrade to a more expensive package that included MySQL database support before I could install WordPress. Once the web hosting was upgraded I had the basic blog up and running in a couple of hours. I registered the domain name to host the blog.

The domain name is fairly self explanatory; I’d be posting articles that in some way related to my life. I thought there would be reviews (of hardware, films, and so on), but the name was generic enough to allow me to put any kind of content on the blog.

My very first post on 5th August 2007 was about setting up the blog on 1and1 (the company I use to host the site). It wasn’t a classic post, but it was a start. That month I posted a few other cheap posts, and also moved some of the content from my failed ‘miscellaneous content website’ over to the new blog.

You should think carefully before deciding to use a self hosted blog like WordPress. Self hosted blogs do require a fair bit of maintenance. At first it was a real pain as all the plugins and the blog itself had to be manually updated on a regular basis. As WordPress evolved it got easier as features such as one-click plugin updates, and then full one-click updates were added.

Over the years I’ve written many posts about the various issues I’ve had to solve with hosting my own WordPress blog on 1and1 such as configuring custom error pages, adding spacing round iframes, and adding a related posts section to each post.

As well as keeping WordPress up to date, you’ll have to dedicate time to customising it (if you want), and backing up your data (very important if you don’t want to risk losing everything). I’d recommend you backup your posts (doing a Tools->Export, and do a MySQL backup) every month. And backup before you upgrade the blog. New minor updates come out every month or two, and major updates seem to come out every three months.

Backing up your blog is very important as not only can you lose data from:

  • Your own mistakes.
  • Mistakes made by your hosting company.
  • Malicious hacking into your site. WordPress has had a steady stream of vulnerabilities being found and patched over the years.

The blog picks up

As time went on I posted more useful information. I got plenty of appreciative comments for my post warning about the Spanish lottery scam, and for a post explaining how to get documents certified cheaply.

The number of comments went crazy when I posted about my experiences of trying to get rid of clothes moths. To date I have 74 comments for this one post, many of them would make worthy posts in themselves. This post is an example of a seasonal post. Clothes moths tend to cause problems in the Spring, Summer and Autumn so these are the times when this post get visitors. The number of people looking for information on moths goes down a lot in the winter.

Getting feedback from other people is one of the most satisfying aspects of writing a blog. I find that when I post about personal experiences I get a lot more comments than if I just provide some information.

As well as the clothes moths post, the posts on my cyst removal surgery, and my problem with knee pain and considering a lateral release got plenty of feedback.

In terms of what posts are popular I find that there are two types of posts that get lots of visitors.

  • Personal experiences – like the posts I mentioned above. People like reading about others who are going through similar things to them.
  • Useful information – posts where I’ve provided free useful information such as my 2011 Excel Calendar, and my guide to upgrading the Samsung N140 memory to 2GB get plenty of readers.

Whatever you are writing about I find that if you add quality original material to the internet you will get more readers then if you just re-hash information that already exists.

I’d predict for example that this blog post won’t get very many visitors. There are so many people blogging about blogging that this post will probably vanish in the noise out there. But I still consider it worthwhile to write it so I can look back once I reach 200 posts.

How I write each post

When I started I used to use the WordPress WYSIWYG editor. I found that it wasn’t a great experience. Typing text into a box on a web page isn’t as good as writing text in a word processor. I like having a proper spell checker, and grammar checker ready to use.

I switched to writing my posts in Microsoft Word and using a set of VBA macros that add the WordPress mark-up to the post.

I don’t have a fixed length for each post, some are very short being just a few hundred words long, and others are many thousands of words long.

The shortest posts have been done in less than half an hour, whereas the longest posts with original research, photos and charts have sometimes taken me four to five hours to complete.

Often I don’t have a plan for each post, I just start writing and finish when I think the post is done. Take this post for example; I have very little idea where I’m going after this sentence! All I have is a few notes about certain topics I want to include.

I didn’t always include photos in my posts, but more recently I’ve tried to have at least one photo or diagram in each post. I think the sight of a large block of text can be off-putting to blog readers. A few relevant (or even not so relevant) photos can help to break the text up. All my photos are taken with a Sony Cybershot W80 camera which I reviewed on this site in 2008.

To upload the photos I use the FileZilla FTP client which has useful functions such as directory bookmarking, synchronised browsing, and filters.

Getting ideas for posts

As my blog is a multi-topic one rather than being a specialised one I can think of ideas for posts all the time. The problem is that I don’t have time to write many of them up.

reviewmylife thumbnails

Often my ideas are topics that I’ve tried to find out about on the internet, had no success, and so have decided to write about them myself.

I find that if I get an idea for a post, I need to write it down right away. If I don’t then I’ll have probably forgotten a few minutes later. If I’m at my computer I record my ideas as a simple list in Word. If I’m away from my computer I put the ideas in a ToDo list on my phone.

If I have specific ideas for what content should be in those posts then I might jot down a few bullet points, but most of the time I just write the idea down in a single line.

Promoting the posts and website

I spend very little time on promoting each post or SEO compared to the amount of time spent writing new content. But I have done some simple things to make sure each post has basic SEO hygiene factors.

  • I’ve installed the All in One SEO Pack plugin, and I make sure I add a title, description, and keywords for each post.
  • I add tags and a category to each post.
  • I submit most of my new posts to Digg, reddit, Delicious, and StumbleUpon.
  • More recently I’ve installed the Tweetly Updater plugin so Twitter is notified when I make a new post.
  • The Google XLM Sitemaps plugin is installed on this blog to make it easier for search engines to index my blog.
  • I have a TweetMeMe Retweet button on my posts to allow other people to Tweet about them.
  • I have an AddThis button on my posts to allow them to be easily submitted to social bookmarking sites.

One area where I haven’t put much/any effort into the blog is with the look. At the time of writing this 100th post I’m still using the default Kubrick theme. I will probably customise it at some point, but may wait until the default theme changes in WordPress 3.0 before I do that.

The Kubrick theme may be basic, but it works well and means I don’t get incompatibility problems each time I need to upgrade the blog. You can get plenty of readers without having to use a fancy theme.

Here is a graph showing the number of visitors I get per week which goes back to when I first installed Google Analytics. The left of the graph is October 2007. The right side is the day I made this post; 27th March 2010. The number of visitors is not huge, but at least it is growing.

visitors per week

Monetising the blog

I decided early on to monetise the blog. Not to make real money, but to at least pay for the costs of the web hosting, and domain names. To do this I use the AdSense Injection plugin with a number of custom tweaks.

It inserts text adverts into the posts automatically, and randomises their position. I find it to be a very easy way of generating a small amount of money for the site. It covers my web hosting costs, but isn’t enough to give up the day job just yet!

If I’m writing a post about something that can be bought from Amazon then I might add an Amazon affiliate link as well. This worked particularly well when I reviewed the Samsung N140 netbook. The review has nearly paid for the netbook already!

Where do my visitors come from?

This site may look like a blog, but in reality I treat it more like a static website that just happens to be using WordPress as the content management system.

Blogs usually have some common theme through their posts, mine are on quite random topics.

Because of my scattered topics almost all my readers come from search engines. I have very few – almost zero – subscribers. People use Google, Yahoo, or Bing to search for something specific, and sometimes they find one of my pages in the results.

82% of my visits come from search engine queries, and 75% of those are from Google.

You might have noticed that quite a few of the list item in the ‘Promoting the posts and website’ section above were relating to social bookmarking websites. However only about 1% of my traffic comes directly from these kinds of sites. It does make me wonder if it is even worth submitting the pages to these sites at all.

Of course these social bookmarking sites may be driving visitors in other ways – by increasing the rank of my pages in the search engines. I don’t think there is any way to find out, but I’ll keep submitting for now.

The top referring social bookmarking website for me is StumbleUpon.

In terms of which country my visitors come from 41% are from the UK, 25% from the US, and India, Canada, Australia, the Netherlands, and Germany are all in the low single figures. In the last month I had visitors from 122 different countries.

Internet Explorer is the most popular browser with 48% of my visitors using it. Firefox gets 34%, Chrome 10%, Safari 5% and Opera 1%.

The future

So what does the future hold for this blog?

Quite simple – more posts! On average I’m posting about one post per week, but sometimes there will be several in a week, and then none for a few more weeks.

I hope to keep to at least this amount of posts for the next year, and work my way towards 200 posts. I have a big backlog of post topics to write about so I won’t run out of ideas anytime soon. And I hope my writing is getting better as I go on.

If you read this I’ll say ‘thanks’. And do pop back sometime soon.

Writing WordPress posts offline in Word with the help of VBA macros

Monday, February 15th, 2010

If you want to write your WordPress posts offline (i.e. in a separate editor to the WordPress editor), then you may find you have to spend a fair bit of time reformatting the blog post to add any required WordPress formatting before you can publish.

There are lots of reasons for wanting to write your WordPress blog posts offline. You may not have access to the internet at the time you are writing. You may find the WordPress editor to be a pain, or maybe you have another editor that you’d much rather write with.

I like writing using Word 2007 so I created some VBA macros which allow me to add bits of formatting to the post (titles, links, photos) faster than I could do manually.

wordpress word 2007 macros

These macros help you format posts which are meant to be pasted into the WordPress non-WYSIWYG post editor. I don’t know what would happen if you pasted posts formatted with these macros into the WordPress WYSIWYG editor.

Description of WordPress macros

Here’s a description of the macros from the source code at the end of this post. I’m only describing the main macros, not the other supporting functions in the code that these macros need.

BoldForWordPress – Adds ‘Strong’ tags around the highlighted text and also makes the text bold in Microsoft Word to make the titles easier to see when you are editing your blog posts.


Will be turned into:


PhotoLinkSite1 / PhotoLinkSite2

Changes the image name into an image link with just a few bits for you to fill in to complete the HTML. It will try to auto generate an ALT tag from the image name by turning any hyphens ‘-‘ into spaces. Highlight an image name such as ‘myimage.jpg’ and click the image button.


Will be changed into:

<img src="http://www.????"
 width="" height="" alt="wordpress blog" />

If you have multiple sites then you can use the template code in PhotoLinkSite1 / PhotoLinkSite2 to allow you to create links which already contain each of your sites URLs. If you only have one site then just delete PhotoLinkSite2.


Listify will convert a number of lines of text into a HTML list.

Item 1
Item 2
Item 3

Will become:

    <li>Item 1</li>
    <li>Item 2</li>
    <li>Item 3</li>

The code will give you an extra list element at the end in case you want to add more items to your list. If you don’t want it just delete it.


Highlight some text or a URL and this will create your <A HREF… link. If you highlight text beginning with ‘http’ then it will put the text into the link section, otherwise it will put it into the description section.

This is some text

Will become:

<a href="">This is some text</a>


Will become:

<a href=""></a>


This will insert a piece of fixed HTML which can be used to add extra spacing to images or Amazon iframes. See my post Adding spacing round an iframe in WordPress for more information. If you select the iframe HTML the spacing table will be put around it. If you have nothing selected then the spacing table will just be inserted straight where the cursor is. This is what will be inserted:

<table border="0" cellspacing="10" align="right">


This macro is useful if you use the Adsense Injection plugin. Press it once and it will insert a tag to disable AdSense in the current post. Press it again and you will get the tag to start the AdSense from a certain point in your post. Here are the two tags it will insert.



This inserts a line of hashes and asterisks into the text. This isn’t useful for the WordPress blog post, but I use it to split up sections in the Word document when I’m writing multiple posts. This is what this macro outputs:


How to create and configure the toolbar buttons

Here are some brief instructions for how to setup these macros. You’ll need the source code below.

First click on the ‘View’ tab and then the ‘Macros’ button on the right hand side of the ribbon.

word 2007 macros button

If you haven’t added any macros before you’ll need to create a dummy one so you can access the Visual Basic macro editor. Type in ‘Dummy’ as the macro name and press ‘Create’. You’ll be taken straight to the editor.

create dummy word 97 macro

Paste all the macro VBA source code below into the editor. Save the macros by going to the File menu and pressing ‘Save Normal’.

Now you need to create some buttons and link them to the macros. Click on the little down arrow (pictured below) to get the Customize Quick Access Toolbar menu. Press ‘More Commands’.

customize quick access toolbar

In the ‘Choose commands from’ pull down list select ‘Macros’.

choose commands from menu

Now click on each of the macros and then press ‘Add’.

adding macros to the quick access toolbar

To give each macro a unique icon, click on each on in turn, press ‘Modify’, and then choose your icon.

add icons to macros

You should now have your macro buttons setup and it will look something like this.

wordpress word 2007 macros

Visual Basic (VBA) WordPress macro source code

Here is the VBA macro code – it’s not pretty but it works. It has been tested on Word 2007. You should be able to get it working on other versions of Word as well, but it might require minor modifications if it doesn’t work as expected.

You might want to customise the URLs in PhotoLinkSite1 / PhotoLinkSite2 to fit your own blog.

Sub BoldForWordpress()
    'Wordpress bold title
    Dim TitleStr
    TitleStr = Selection.Text
    Dim HasNewLine As Boolean
    If Right(TitleStr, 1) = Chr(13) Then
        HasNewLine = True
    End If
    TitleStr = TrimNewLine(TitleStr)
    With Selection
    .Font.Bold = wdToggle
    .TypeText ("<strong>")
    .TypeText (TitleStr)
    .TypeText ("</strong>")
    .Font.Bold = wdToggle
    End With
    If HasNewLine Then
        Selection.TypeText (Chr(13))
        Selection.Font.Bold = wdToggle
    End If
End Sub
Function TrimNewLine(Str) As String
    'Remove newline from string
    If Right(Str, 1) = Chr(13) Then
    TrimNewLine = Left(Str, Len(Str) - 1)
    TrimNewLine = Str
    End If
End Function
Function TrimPlus(TheString) As String
    'Trim space and newline
    TheString = Trim(TheString)
    TrimPlus = TrimNewLine(TheString)
End Function
Sub Replace(FromStr, ToStr)
'Replace text in the current selection
    With Selection.Find
    .Text = FromStr
    .Replacement.Text = ToStr
    .Forward = False
    .Wrap = wdFindStop
    .Format = False
    .MatchCase = False
    .MatchWholeWord = False
    .MatchWildcards = False
    .MatchSoundsLike = False
    .MatchAllWordForms = False
    .Execute Replace:=wdReplaceAll
    End With
End Sub
Sub PhotoLinkSite1()
Call PhotoLink("http://www.????")
End Sub
Sub PhotoLinkSite2()
Call PhotoLink("http://www.????")
End Sub
Sub PhotoLink(LinkBase As String)
    'Turn the image name into a link
    Dim PicString, AltString
    PicString = Selection.Text
    ' Remember newline
    Dim HasNewLine As Boolean
    If Right(PicString, 1) = Chr(13) Then
        HasNewLine = True
    End If
    PicString = TrimPlus(PicString)
    'Create alt text
    Call Replace("-", " ")
    Call Replace(".jpg", vbNullString)
    Call Replace(".png", vbNullString)
    Call Replace(".gif", vbNullString)
    AltString = Selection.Text
    AltString = TrimPlus(AltString)
    'Write HTML
    With Selection
    .TypeText ("<img src=""")
    .TypeText (LinkBase + PicString)
    .TypeText (""" width="""" height="""" ")
    .TypeText ("alt=""" + AltString + """ />")
    End With
    ' Re-add new line
    If HasNewLine Then
        Selection.TypeText (Chr(13))
    End If
End Sub
Sub Listify()
    'Add list tags to a plain text list
    Dim ListString
    Call Replace(Chr(13), "</li>" + Chr(13) + "    <li>")
    ListString = Selection.Text
    Selection.TypeText ("<ul>" + Chr(13) + "    <li>")
    Selection.TypeText (ListString)
    Selection.TypeText ("</li>" + Chr(13) + "</ul>")
End Sub
Sub SpacingTable()
    'Add a table which puts space around Amazon
    'product links
    Dim TableString
    TableString = Selection.Text
    TableString = TrimPlus(TableString)
    With Selection
    .TypeText ("<table border=""0"" cellspacing=""10""")
    .TypeText (" align=""right""><tr><td>")
    .TypeText (TableString)
    .TypeText ("</td></tr></table>")
    End With
End Sub
Sub Link()
    'You can either select some plain text or a
    'URL to be turned into a link
    Dim LinkString
    LinkString = Selection.Text
    Dim HasNewLine As Boolean
    If Right(LinkString, 1) = Chr(13) Then
        HasNewLine = True
    End If
    LinkString = TrimPlus(LinkString)
    If Left(LinkString, 4) = "http" Then
        Selection.TypeText ("<a href=""")
        Selection.TypeText (LinkString)
        Selection.TypeText ("""></a>")
        Selection.TypeText ("<a href="""">")
        Selection.TypeText (LinkString)
        Selection.TypeText ("</a>")
    End If
    'Fix up the new line
    If HasNewLine Then
        Selection.TypeText (Chr(13))
        Selection.TypeText (" ")
    End If
    'Put the cursor in the correct place so you
    'can complete the link
    Selection.MoveLeft Unit:=wdCharacter, Count:=4
    If Not Left(LinkString, 4) = "http" Then
        MoveCount = 2 + Len(LinkString)
        Selection.MoveLeft Count:=MoveCount
    End If
End Sub
Sub Splitter()
'Easily visible line for dividing posts
Sp = "*#*#*#*#*#*#*#*#*#*#"
Selection.TypeText (Sp + Sp + Sp + "*#*#" + Chr(13))
End Sub
Sub Adsense()
'For use with Adsense Injection plugin
NoAdsense = "<!--noadsense-->"
If Selection.Text = NoAdsense Then
    Selection.TypeText ("<!--adsensestart-->")
    Selection.TypeText (NoAdsense)
    With Selection
    .MoveLeft Unit:=wdCharacter, Count:=16, Extend:=wdExtend
    End With
End If
End Sub

Tips for upgrading to WordPress 2.9 on 1and1

Thursday, December 24th, 2009

A few days ago I upgraded the my blog from WordPress 2.8.5 to 2.9. Here are some tips on what I did in case you run into any of the same issues that I did. That blog is hosted by 1and1 and some of the information may be specific to them.

This isn’t meant as a full upgrade guide – just a collection of tips that may help you.

First make sure you backup your data! There are some general wordpress backup tips on a post I did about a previous upgrade.

1. Export the SQL database

In the MySQL admin panel I selected these extra options: ‘Add DROP TABLE’ and ‘Complete inserts’, and then chose to save the file as a .gz (gzip) archive. If you need a free application to read .gz archives then I recommend 7-Zip.

Oneandone MySQL icon

2. Export the XML data

Export the XML post data from the WordPress admin panel (Tools->Export).

3. Zip and downloaded the blog files

Zip up the actual files on the server. On 1and1 the easiest way to do this is to logon to your admin panel, go to the Webspace Explorer, right-click on the directory and select ‘zip’.

You can then right-click on the zip file and choose download to copy it down to your computer.

4. Verify the data

I verified that the exported SQL data, XLM and .zip files were valid. The easiest way to verify the SQL and XLM data is to look at it in a text viewer such as NoteTab Light and make sure that the data at the end of the file is valid. Sometime a download can silently fail and you can end up with truncated data. If you try to restore the data from a truncated file then the restore will fail.

Verify the .gz file by making sure it will open in 7-Zip.

Click on the upgrade button

I finally was ready to click on the upgrade button. I clicked on it and a second or two later I got the message:

‘The update cannot be installed because WordPress 2.9 requires MySQL version 4.1.2 or higher. You are running version 4.0.27’

How I got around it

The partial answer is contained in the post here. However I’ll add a few bits of information on what I did differently.

I created a new MySQL 5.0 database from the MySQL admin panel. On the old 1and1 business hosting package I think you can create two MySQL databases (or up to 10 on the newer business hosting package) so you don’t need to delete the existing one first. Don’t delete it – you may need it if everything goes wrong with the upgrade!

I didn’t import the data by using the XML backup. I imported the data into the new MySQL 5.0 database from the gzipped SQL archive that I’d created in step 1 above.

You can import the SQL data from the MySQL admin panel by going to the tab to execute SQL commands, and then selecting the .gz file. Importing the SQL file through a .gz file gets around the 2MB size limit in the MySQL admin panel.

Importing from the .gz file rather than the .XML will import all your database data, and plugin settings, whereas if you do it from the .XML file you may have to manually re-enter various settings into your blog.

In your wp-config.php you will have to ensure that the DB_NAME, DB_USER, DB_PASSWORD and DB_HOST have been updated with the settings of your new MySQL 5.0 database.

Upload the wp-config.php file and if everything has gone right your blog should still be working and look exactly the same as before. Your blog will be using the old version of WordPress but will be accessing the data from the new MySQL 5.0 database.

You should now be able to click on the upgrade button and the blog should upgrade in less than 5 seconds.

This worked fine for me on 1and1. If you have loads of plugins or a heavily customised theme you may find more problems. If this is the case you can try deactivating plugins, or switch to the default theme.

If you really can’t get things to work you should be able to roll back to your pre-2.9 WordPress blog by restoring the files that you zipped in step 3 above. You MySQL 4.0 database should still be there (as long as you didn’t delete it).

Upgrading WordPress can often be a pain but at least having upgraded the SQL database from 4.0 to 5.0 should avoid more problems in the future. And now with WordPress 2.9 you can look forward to batch updating your plugins rather than doing them one at a time!

Upgrade WordPress to 2.8.1 on 1and1

Tuesday, July 14th, 2009

In the bad old days upgrading anything WordPress related (plugins, themes, or WordPress itself) would at best involve manually downloading a zip, extracting it locally and then using FTP to upload the changes to your web server. At worst it could require manually editing files, and making database changes.

In February last year I wrote about how cool it was that the All in One SEO Plugin had a one-click upgrade facility. Updating plugins had always been a big pain, especially when you have a blog with many plugins (this one has about 10) so it was great when WordPress introduced one-click plugin upgrade support. Although plugins could now be upgraded with a single click, upgrading WordPress itself was still a manual task.

In WordPress 2.7 they introduced one click upgrade support of WordPress itself. When 2.8.0 was released a message at the top of my blog console prompted me to do a one-click upgrade. I decided to wait. Upgrading to a x.x.0 release can be risky. These are major updates and often have many bugs. Waiting until the x.x.1 release can be safer unless there is an urgent reason to upgrade (such as a critical security update).

Another reason for delaying a WordPress upgrade is that it can take a while for the plugins that you use to be updated to be compatible with the new version. Sometime no changes are needed, but when WordPress update their database structure, plugins are particularly vulnerable to breaking.

Even though you can now upgrade from 2.7.x to 2.8.x with one click, upgrading is never that simple. With each upgrade there is a chance that you will completely trash your blog.

Firstly make sure you have plenty of time. If it goes well it shouldn’t take too long. What you don’t want to do is for it to go badly wrong and end up with your blog trashed, just before you have to leave for an urgent appointment.

You MUST do your backups before upgrading. Before backing up I make sure all the plugins are up-to-date and I delete any comment spam so this isn’t backed-up.

I always do three different backups.

  1. File backup – I FTP all the blog files down to my computer.
  2. XML export – Export all the blog information as an XML file using the Tools->Export option.
  3. MySQL database backup – A full MySQL database backup using the backup instructions from the official WordPress website. On 1and1 you select the MySQL admin panel using the highlighted button shown below.

Oneandone MySQL icon

After backing up I verify that the backups look correct. I generally diff the XML and database dump to my previous backup using the Beyond Compare tool. The main thing to check is that the backups haven’t been truncated due to a failed download. If the files are much smaller than previous backups then you may have a problem.

I’d read that in order for the upgrade to work on 1and1 you need to ensure that your website is processing .php files using PHP5 rather than PHP4. To ensure this you must have the below line in your .htaccess file in the root of your blog.

AddType x-mapp-php5 .php

After all this there was just one thing left – to press the ‘Upgrade’ button.

I pressed it and held my breath. Some messages appeared on the screen and about 10-15 seconds later it said the upgrade had succeeded. At first I thought something must have gone wrong, as it was so quick. I logged back into the blog and saw that it had worked!

The only problem that I found was due to me having made some changes to the default theme. These changes had been overwritten. Luckily due to the file backup that I had made by FTP I was able to restore them in a few minutes. The lesson to learn here is not to change the default theme. You should copy it to a new directory and only change the copied version. If you want to keep any updates to the default theme in sync with your modified theme you may have to manually merge them in, but at least you won’t lose your theme updates.

Congratulations to the implementers of this feature in WordPress. It is much appreciated by me :)

Speeding up a WordPress blog with caching

Monday, August 4th, 2008

I decided to investigate some methods of speeding up page load times on my this blog.

An obvious way to do this seemed to be to add some caching to the site to reduce the load on the MySQL server.

Searching for WordPress caching information gives a lot of references to adding a define('WP_CACHE', true); line to your wp-config.php file. However this information is now out of date. The WordPress file-based object cache was removed in version 2.5.

I decided on the WP Cache 2.0 plugin which stores the generated pages in /wp-content/cache/ and then serves them to your readers. It does this completetly transparently.

Two questions that I did have about WP Cache before I installed it were:

  1. Does it work with Google AdSense?
  2. Will Google Analytics still work?

The answer to both of these questions is yes!

I’ve been using the plugin on my other blog for about a week now with no problems. The speed difference is noticeable but small. You may notice a bigger difference if you have a more popular blog than mine.

AdSense Injection WordPress plugin tweaks

Thursday, July 24th, 2008

Update 7th December 2010: Use the new Ad Injection plugin for WordPress instead as it will do what these tweaks do, and more.

On this blog I use the Adsense Injection plugin to automatically add Google’s targeted AdSense adverts to my posts. The plugin is excellent and has helped to make more money for this site but there are a few tweaks that I have done.

First, I’ve made a modification so that if a individual post page is shorter than a certain number of characters then the number of adverts is limited to one.

Second, I’ve made a change so instead of looking for ‘<p’ tags to use as AdSense insertion points it looks for the full paragraph tag – ‘<p>’. The reason I did this is because I often include code in my posts in <pre> tags and the AdSense plugin code was inserting adverts in my source code snippets which looked wrong. After making this change the adverts only appear in the text of my posts.

Both sets of changes are shown in the code below. You can simply replace the ai_the_content() function in version 2.0 of the plugin with this version.

function ai_the_content($content){
  global $doing_rss;
  if(is_feed() || $doing_rss)
    return $content;
  if(strpos($content, "<!--noadsense-->") !== false) return $content;
  if(is_home() && get_option('ai_home') == "checked=on") return $content;
  if(is_page() && get_option('ai_page') == "checked=on") return $content;
  if(is_single() && get_option('ai_post') == "checked=on") return $content;
  if(is_category() && get_option('ai_cat') == "checked=on") return $content;
  if(is_archive() && get_option('ai_archive') == "checked=on") return $content;
  global $ai_adsused, $user_level;
  if(get_option('ai_betatest') == "yes" && $user_level < 8)
    return $content;
  if(get_option('ai_notme') == "yes" && $user_level > 8)
    return $content;
  # RML: backup content
  $original_content = $content;
  $numads = get_option('ai_nads');
    $numads = get_option('ai_nadspp');
  $content_hold = "";
  if(strpos($content, "<!--adsensestart-->") !== false){
    $content_hold = substr($content, 0, strpos($content, "<!--adsensestart-->"));
    $content = substr_replace($content, "", 0, strpos($content, "<!--adsensestart-->"));
  while($ai_adsused < $numads)
    $poses = array();
    $lastpos = -1;
    # RML: change <p to <p> to stop ads before <pre>
    $repchar = "<p>";
    if(strpos($content, "<p>") === false)
      $repchar = "<br";
    while(strpos($content, $repchar, $lastpos+1) !== false){
      $lastpos = strpos($content, $repchar, $lastpos+1);
      $poses[] = $lastpos;
    //cut the doc in half so the ads don't go past the end of the article.  It could still happen, but what the hell
    $half = sizeof($poses);
    $adsperpost = $ai_adsused+1;
      $half = sizeof($poses)/2;
    while(sizeof($poses) > $half)
    $pickme = $poses[rand(0, sizeof($poses)-1)];
    $replacewith = ai_pickalign(get_option('ai_lra'));
    $replacewith .= ai_genadcode()."</div>";
    # RML: remove hardcoded length
    $content = substr_replace($content, $replacewith.$repchar, $pickme, strlen($repchar));
    # RML: if content is short then limit to one advert
    if(strlen($original_content) < 2500) return $content_hold.$content;
  return $content_hold.$content;