Version control with WordPress

I presented at the Chicago Northside meetup talking about version control with WordPress. This popular meetup is always well attended and this was no exception.

In the presentation I aimed to demysitify version control and

  • Cover some of the whys, whats, and hows
  • Cover some of the tools
  • Help understand some of the things we can track with version control
  • Demonstrate some basics
  • Describe the benefits to any type of business / developer

Continue reading

Contact Form 7 autocomplete

I found Chrome was warning me of form markup improvements I could make to input elements on my Contact Form 7 forms. Chrome displays messages in its developer console like this:

Showing suggested form markup improvements

Suggested form markup improvements

I took the time to see what I could do to get rid of these warnings and after checking the CF7 documentation I saw it was easy to update my forms with the following parameters.

<label>Please enter your Name (required) [text* your-name autocomplete:name] </label>

<label>Please enter your Email (required) [email* your-email autocomplete:email] </label>

I added “autocomplete” then a parameter from the HTML spec to meet standards. So for the “name” field the suggested update would be “autocomplete:name”. Contact Form 7 then correctly added the autocomplete markup when putting the form on the page and now the forms are compliant with standards and I don’t see these console warnings.

Git stash

I use Git when working on my WordPress projects.

On occasion, when I’m working on the latest branch and testing out some changes, styling, code etc, I’m *really* excited that I’ve squashed that bug / made that visual improvement.
However, it’s only then that I realize I didn’t create a new branch for my current round of changes.

So, it’s copy/paste, multiple CTRL-Z’s and then paste in. But wait! The changes are in multiple files. Darn.

Have no fear. Git can help.

Continue reading

WordPress plugin – Featured Image Admin Thumb

I am happy to share my latest WordPress plugin.

Inspired by a recent site I was working on, this plugin helps identify the featured image that is associated with each Post or  Page.

Find out more about the plugin and try it out for yourself.

Featured Image Admin Thumb – WordPress plugin

*Update* – this plugin is now hosted, updated and available from the WordPress plugin directory – here’s the link to Featured Image Admin Thumb on the directory.

** Double update ** – I’ve added more features to this plugin and the latest version is now available.

WordPress Backups

Backups. Everybody talks about them and says they are doing them, or going to do them or definitely going to do them. However, sometimes the truth is no backup is in place. I wanted to raise awareness and encourage backups for WordPress site owners by describing one of the backup options in the WordPress field.

WordPress backup with PressBackup and Amazon S3

Talking at the Chicago Northside WordPress meetup on Updates, Backups and maintenance I described how you could configure a WordPress backup solution, PressBackup, to work with Amazon S3. By using Amazon S3 you get the benefit of  potentially unlimited backup file storage for free (12 months initially) or for relatively low cost. You create an account with PressBackup and then you can use your Amazon account by adding the S3 service (a few sign up steps), retrieve the Amazon security and authentication keys and put them into PressBackup and then the backups can begin.

Continue reading

Add a bit of style to the WordPress categories widget

By default the WordPress categories widget offers quick and easy links to your content categories. With a little bit of CSS you can easily make some stylish additions to the output.

So, here’s the before shot:


But in this case I want to add little style, some graphics or perhaps some Font Awesome – something like ” ” (quotes at the beginning or end) or &raquo suffixes to the category links. Now, sometimes you can add some filter code (requires programming knowledge) that works with widgets to modify the output but with the Categories widget  the only amendment you can make is to exclude select categories. The default categories widget doesn’t offer content or style changes in that way so we’re pretty much stuck with its default output.

If you wanted to you can clone the default categories widget code (requires programming knowledge), include it in your theme and make modifications – perhaps just adding the extra character – and you then have the choice of widgets to use.

However, there’s a slightly easier way that only requires the ability to add some CSS to your theme (requires no programming knowledge) and you can make these small style changes changes. For this example I am showing you some code that will add a quote around the category name and » to the end of your category name.

The categories widget outputs the categories in an block like this:

<li class="cat-item"><a href="/category/bananas">Bananas</a></li>
<li class="cat-item"><a href="/category/apples">Apples</a></li>

We will hook into the cat-item class and use CSS psuedo elements (including legacy browser support) and add the code for raquo, “00BB” into the :after element.

.cat-item {
    *zoom: expression(
    this.appendChild( document.createElement("small") ).className="after"
.cat-item {
/** Any other specific cat-item styling can go here */

.cat-item .before,
.cat-item:before {
        content: '\201c'; /** Open quote **/
.cat-item .after,  /* IE6/7 */
.cat-item:after {
    content: '\201d\00BB'; /** Close quote and brackets */

And here’s the after shot:


So with a small bit of CSS and no programming you can easily add many embellishments to your categories or in fact any other list. And you can get fancier with your CSS by playing a little more perhaps with inspiration from

Legacy support code – thank you:

WordPress issue – ‘blog pages show at most’ not working

While working on a client project I thought it would be best to use real content from the clients site to check, amongst other things, if pagination was working on the home page.

After importing the clients data into my development site I refreshed the the home page and looked for pagination at around 10 posts (the default).

Not so – the home page filled up with posts and right at the bottom was my post navigation – older / newer posts links.

I visited the WordPress Settings, Reading page and changed the “blog pages show at most” settings to a different number and refreshed the page.

Again nothing changed.

This time I search to see if this was a known issue (can’t think why it would), I checked my index.php code and compared to other theme files, I switched to the default WordPress theme and still the homepage filled up with posts.

Finally after more searching I came up with the solution – sticky posts.

It was then that I realized that all the posts in the client data (over 300) were set to sticky.

That’s why the pagination wasn’t working.

Now, in the WordPress Admin Dashboard I’ll have to uncheck “Make this post sticky” for each post or (perhaps a little faster) manually change one option in my wp_options table to changes the sticky settings.

If you are comfortable messing with your WordPress database you can reset the ‘sticky_posts’ option in the wp_options table. I made the following change to the ‘sticky_posts’ field in my development database. I edited it to be “a:0:{}” and all the sticky posts were gone!

A simple solution to cap off some head scratching and I hope this helps you out if you encounter the same issue.

Post comments not allowed if comment metabox removed

When building a site for clients it’s nice to clean out the Admin Dashboard screen of some of the unnecessary (and possibly dangerous) sections and checkboxes to avoid distractions when creating or editing their content. WordPress is flexible enough to allow sections, or meta boxes, to be easily removed through the use of the remove_meta_box function. The code can be added to the functions.php file.

One of the meta boxes that can be removed is the Comments or Discussion meta box. This box lives in the lower half of the Edit post screen. It allows you to set the post, or page, to accept or deny comments and trackbacks/pings. I’ve been working on a couple of sites for some clients and it was originally decided not to have comments at the launch. I removed the comments options from the post screen and removed the call to the comment template in the sites theme files.

Then the client changed their mind and would like comment functionality restored. Now, it’s some time into the life of the site and the previously created posts are showing that comments are closed and the client want to add the ability for all posts to allow comments. It is easy to edit the theme files and add back in the “comment_template()” code and that would be that. However, the posts still show “Comments are closed”.

In Settings, Discussion there are no restrictions for commenting so it’s a little confusing that comments are not showing.

After working a little further on this I found the trick, which can be a little time consuming if you have lots of posts. Either edit, or quick edit, each affected post and tick the box that says “Allow Comments”.

Allow Comments in edit post

Allow Comments in edit post

After doing that for each post you should find that normal comment functionality is restored for all posts and for new projects I always try and identify the comment requirements at the outset.

Slow WordPress tag queries

While working on a real estate project I encountered very slow response from WordPress on certain queries. These queries are multiple tag queries in the form:

My application is using WordPress tags to annotate the content and I am providing links to those multiple tag queries throughout the site. Over time and while I was developing the site I noticed the site response getting slower and slower when I clicked on these links and yet there are times when the response was within the acceptable range. My hosting service was also affected and I was seeing high CPU usage when one of these queries was triggered. I decided to investigate.

I bounced between my Apache configuration, my MySQL configuration and the external database I was also querying. I had used the external database in a previous project and I was fairly confident I had not introduced any issues there. The queries I was performing were responding well within acceptable times and using mtop on my hosting console I was seeing WordPress queries hogging the resources.MySQL query

I changed the settings in my MySQL configuration file to increase buffers, heaps, table sizes and more. Improvements were minimal where there were any and in other cases no change. I didn’t think I was doing anything beyond the scope of WordPress (although I always like to learn) so I started searching to see if anyone else was experiencing the same or similar issues.

I found the usual and variable guides on how to speed up WordPress and more about taxonomy queries. I found there were reports of issues after a recent WordPress upgrade – support questions were posted here and here.

Digging deeper I did come across a WordPress Trac ticket and that seemed to be very similar to my issue.  I have been keeping my installations up to date so I could see that I became affected at that same upgrade point. Reading the Trac ticket it seems a resolution to this issue is due in the next release of WordPress (3.2) but I wanted to find out if it really did fix my issue. I upgraded my site to 3.2 beta and applied the patch mentioned in the ticket. The difference is huge and the site response time is much closer to where it should be.

Reading through the Trac ticket the explanation of the issue and the fix is purely down to optimization of the query built when WordPress is required to display information based on multiple categories or tags.

**UPDATE**: It seems that these multi tag queries are operating efficiently after upgrading to WordPress 3.2+ and this hint/tip might no longer be valid or required.

Importing data into WordPress

I’ve been working on a project that requires me to reference an external database of property listings – 106,000 of them – and display these listings in WordPress.

One way I thought of was to create a plugin to read the listing data into WordPress, create a post and custom meta fields (or even a custom post type) with all that listing information and then categorize / tag each post allowing themes to organize the listings as needed. I reviewed that idea didn’t think it was necessary to duplicate the real estate listing data in the WordPress database.

But, if I could create posts with ids that match the listing id then with the help of a shortcode, I could create posts and the shortcode would pull the listing data when a post is viewed.WordPress Import Real Estate Listings

I thought it would work so I reviewed the wp_insert_post function in the Codex and found it had a parameter “import_id”. Now, if I could make that import_id match the real estate listing id I could easily use the categorization and tagging capabilities of WordPress to organize the posts. When populating the WordPress site I query for and retrieve the listing ids from the database, get the id and create the post. Then, just after the post creation process I further query the listings database and create the categories and tags I need assigning them to each post id.

With all the listings referenced in WordPress I can search on and display posts by category and tag or include some external searching capability to get the IDs I want and then use WordPress to display the listings that matched the search.

For the purposes of the project this method worked, but with one side effect. All the menus, pages and other WordPress elements are numbered like the posts. So, at some point, there may be a clash between a numbered menu item and a real estate listing with the same id but I’ve yet to hit it.

« Older posts