CSS Naked Day

It is CSS Naked day, hence my stylesheet is turned off. Lorelle explains CSS Naked Day better than I ever could.

WordPress Shortcodes: what? why? how?

WordPress 2.5 implemented a new way of inserting content into posts: shortcodes. If you haven’t had the need to use the new gallery shortcode you might not have come across the details. So, what are they?

Plugin authors have used all sorts of methods of adding codes to posts to specify where the content of their plugin should be included. Shortcodes takes this idea, and builds a standard method into WordPress.

There is one included in WordPress 2.5 by default and that is the gallery shortcode. The gallery shortcode inserts all of the images that are attached to the post into that post using one simple code that looks like this: [gallery]

Shortcodes also accept options so, for example, if you wanted to include the gallery from a different post you can specify the post id, like this: [gallery id=”6″]

The gallery shortcode also lets you specify the order of the images, the size, the way they are marked up, by default it uses a definition list, and the number of columns. You can read more about the options in the gallery shortcode at the WordPress Codex.

Shortcodes can even be used to surround text, if the plugin requires it: [code]Some text here[/code]

Shortcodes should help to bring consistency to the way plugins work, helping users to get to grips with them more easily, but also help plugin authors. There is an easy to use API that takes the work out of producing plugins that find and replace content, or even just insert it, with options.

I have used it for one plugin so far. Fun with Photo Data displays EXIF data in a list. While it wasn’t difficult to create without shortcodes, using the Shorcodes API made it easier still. For complex plugins this could be make a significant difference.

My WordPress plugin generator has been updated to include shortcode functionality and you can read more information about the Shortcodes API at the WordPress Codex.

Tool Update

I have just uploaded a minor update to the Fun with Plugins, Wordpress plugin generator tool, so that it now includes WordPress 2.5 Shortcodes.

Still to come in the near future is support for the new multiple add widgets (once I can get it working consistently) and a lot of more actions and filters.

Solving Plugin Problems

Since releasing the first version of my Fun with Sidebar Tabs plugin I have learned a great deal about resolving plugin problems, so I thought I would share a few of the techniques that have proved valuable. I hope this will be as useful to people with problems on their blog as for authors that release their own plugins.

Figuring out why a plugin isn’t working when you don’t have access to the backend, i.e. it is a problem on someone else blog, or if you don’t really understand the code anyway, can be difficult but there are a few good indicators of what might be going wrong.

In many cases the only obvious indication you get is that it just doesn’t work, so where do you look?

I want to specify in no uncertain terms the necessity of reading, in full, the instructions before making assumptions about whether it works or not. I know I have downloaded things assuming they would work in a certain way and had to go back and re-read the instructions when they didn’t, and it was almost always my fault. Make sure it is intended for your version of WordPress as well.

But having done that, and there is still a problem, what now?

The first thing to check is the source of the page that is produced. Plugins that output content using PHP often do it inside other tags that aren’t immediately visible, so check the source code for warnings or errors that seem out of place. They should be fairly obvious if they are there.

If you find that error there probably isn’t much you can do so contacting the author is probably best first step. If you are the author you should know what to do from here.

If the plugin uses Javascript this can be harder to resolve. In that instance check whether there are any Javascript errors showing. Check the error console in Firefox, or the bottom left of the status bar in IE to see if there are errors.

One of the chief causes of my plugin breaking was Javascript errors being triggered before the page was loaded, or before my Javascript was loaded which just stopped mine running. The first indication that there was a problem was that my plugin didn’t work, even though it wasn’t the cause of the problem.

Another thing to check is for plugins that load their own versions of frameworks. WordPress has a system of registering and loading scripts that can be plugged into but some plugins just insert a link to the framework themselves. With the release of WordPress 2.5, which uses Prototype version 1.6, there may be errors where plugins load their own copy of Prototype 1.5, thereby overriding functionality that is expected. I have come across at least one since the release of 2.5

Finally, there is the problem of CSS. CSS priority, i.e. more specific rules, or IDs rather than classes overide other rules, can be a real problem with so many different bits of CSS being loaded and no knowledge of the theme that is being used. Firebug, the firefox development plugin, is essential to figure this stuff out in my opinion. It shows what rules apply and what have been overruled.

Finally, of course, you can turn off all your plugins and turn them on one by one to find out where the conflict lies.

I will add more to this post as and when things occur; however, in the meantime, if you have any tips or suggestions for finding out what is wrong with a plugin or what may be conflicting with it please let us know.