add-rel-lightbox Version 0.4 Released

Upgrade from your WordPress admin panel, or download from wordpress.org/extend/plugins/add-rel-lightbox/

Version 0.4 switches from identifing the link-wrapped images in a page with hacked-together regexes that just about work, to properly parsed HTML structure using PHP Simple HTML DOM Parser.

When I initially tried to release version 0.4 and installed the updated plugin on this site, suddenly the content for half the posts stopped being displayed. After retracting the update, having a small panic, and reviewing the code that had been working without error in testing, I eventually found the culprit of the missing content: a regex in another plugin!

It turns out that the Simple HTML DOM Parser is set to strip linebreaks from the HTML input as standard. It was this operation, on content that otherwise was not altered by add-rel-lightbox that was breaking a (.*?) heavy regex. See also: Death to Dot-Star!

I’ve now changed add-rel-lightbox to leave the linebreaks in the content, so it will return content completely untouched if there are no link-wrapped images in the post. This means that it will play nicely with with other plugins but, if nothing else, this is a good example of why HTML should be parsed properly instead of using regular expressions for all but the most predictable content.


The couple of questions on the plugin’s support forum suggests that add-rel-lightbox is being used with less lightbox-compatible image handlers, so it’s probably a good time to add some configuration options for the plugin. Nothing too complex; just some variables that can be stored so they don’t get overwritten by a plugin update.

add-rel-lightbox version 0.3

New for version 0.3:

  • Adjusted the filter hook priority so it uses the core shortcode function.
  • Also works with the_extract() e.g. on front page and category listings.
  • All images and gallery form one linked gallery per post/page.

Search for “add-rel-lightbox” from your WordPress installation or download the source from:


Where version 0.2 added the capability for add-rel-lightbox to add attributes to image links from the WordPress shortcode, it did replace the WordPress core gallery_shortcode() function. Clearly, replacing a function means having to keep the plugin code updated if there are any changes to the relevant core code, so it’s not an ideal solution. However, at the time, I didn’t know how to ensure the link filter ran after the gallery shortcode.

The answer is in the WordPress codex (codex.wordpress.org/Shortcode_API), where it states:

do_shortcode() is registered as a default filter on ‘the_content’ with a priority of 11.

So just setting add-rel-lightbox’s filter priority means it will run after all shortcodes by default, and the core gallery_sortcode() can be used.

Also from a suggestion from Jason Spatola, version 0.3 also works with the_excerpt, so images in post excerpts also have lightbox attributes added. But so that all the images on the page aren’t called in one single gallery, the rel="lightbox" now has includes the post number.

<a href="/url/to/ima.ge" rel="lightbox[post-$id]" title="Media description"><img…></a>

Gallery images are also supplemented by post ID, so all local embedded images form one linked gallery per post. Continue reading add-rel-lightbox version 0.3

add-rel-lightbox version 0.2

New for version 0.2, the plugin will now also add the lightbox attribute and caption to image linked galleries using the [gallery link=”file”] shortcode.


add-rel-lightbox is a WordPress plugin that will automatically add a rel=”lightbox” attribute and the image appropriate description from the media library to link-wrapped images placed in WordPress posts.

Previously, the plugin only worked with images placed into posts of the exact format used by the “add media” dialogues, and only for images that are in your media library. This means it will not interfere with any images that have already added attributes to.

New for version 0.2, the plugin will now also add the lightbox attribute and caption to image linked galleries using the [gallery link=”file”] shortcode.

In addition to the add-rel-lightbox plugin, to work properly, lighbox (or a lightbox clone such as slimbox) must be active on your site. This can be either as part of your theme, or included as a plugin. If at any time, either component is not activated, the site will revert gracefully to the standard function of “open image as new page”.

So with the plugin activated and your lightbox clone active, using

[gallery link="file"]

in your post will give:


Plugin available at the WordPress Plugin Directory or search for “add-rel-lightbox” in the `Plugins -> Add New` page of your site administration.

Code is available for play with, adjust, fork and modify at GitHub.com/DefProc/add-rel-lightbox, improvements are accepted.

add-rel-lightbox now available as WP plugin

add-rel-lightbox, the code discussed in this post is now available in the WordPress Plugin Directory. This means that you can install it in your WordPress site by searching for “add-rel-lightbox” in the `Plugins -> Add New` page of your site administration.

The code is also hosted at github (github.com/DefProc/add-rel-lightbox/) for you to pull, fork, alter or adjust (git is my preferred revision controller): improvements are accepted.

To make it work, you will also have to have a lightbox/slimbox/lightbox clone installed on your site — either as a plugin, or as part of your theme, however if one is missing or disabled, add-rel-lightbox will fail gracefully and silently. I’m using “slimbox plugin” (also on the WP Plugin Database), which despite not being listed as compatible, continues to work on my up-to-date WP versions.

That is all.

suPHP for Apache in Ubuntu

As part of my learning more about web hosting, I have a VPS that hosts a testing area for this site and I also host a couple of virtual hosts for other people. One of the side effects of the standard server setup that I have been using is that in WordPress, whenever I want to upgrade or install anything, I have to type in my FTP password to give WordPress the privileges to modify files. This doesn’t happen on the hosted server that I currently use for the live site.

I know what the cause of this password requirement is; because the files and directories that make up wordpress are not owned by the the same user that the web server (apache) runs as, the web server has no authority to make changes in those directories. The files are owned by my user ($username) on the system, but apache runs as www-data.

Obviously, the simplest way of sorting this out is just to change the owner of the files to be the same as the apache user, but this is not good practice. It means that the contents of the files can be read and written-to by apache, but it also means that the files can be read-from and written-to by any apache process. This means that any user’s scripts on the system will have access to any other user’s web files through apache. Not too much of a problem if there’s only one user or virtual host, but with more than one, it’s not a great idea.

The other option then is to run php scripts as the user who owns them. Not quite as simple as changing the file owner, but then I’m not the first person to have come to this. There are a number of modules that will alter the owner of the php process based on the owner of the script file, I’ve gone for suPHP.

As it turns out after an hour or so of searching, the process is pretty straight forward, everything is included as part of Ubuntu’s packages. In fact it took less time to implement than it did to research… Continue reading suPHP for Apache in Ubuntu

Add rel=”lightbox” to WordPress Images

Now a WordPress Plugin, see the most recent version releses: Category > add-rel-lightbox


I really like the pop-up display style of lightbox and slimbox, and WordPress has a really nice integration for adding pictures, but the two don’t talk to each other automatically. Getting images insterted from the WordPress media dialogue has a few requirements:

  • Automatically add the rel="lightbox" to a link that wraps an image, but only when the link points to the original image
  • Be able to identify that the inserted image and link is the format inserted from the WordPress media library
  • Add a caption to the lightbox that is correctly formatted to include any html characters. If you have to manually enter lightbox captions for the same picture on every page, then that’s much worse than only entering them once in the media library
  • should fail gracefully if lightbox or slimbox is removed/deactivated
  • Ignore link-wrapped-images that already have lighbox attributes set

What I’ve got in the form of a basic plugin is shown below.
Continue reading Add rel=”lightbox” to WordPress Images

Choosing a Blog Platform

If you want to self host a blog, there are two main contenders:

Now, I’d already decided to not use MODx, as used in the main site, as the blog engine. MODx can function as a blog, and the demo site includes one, but it don’t have the expertise with MODx to get as complete a product as two above. I don’t suppose I’m much different from most people who set up a blog; they’re not specialists, but they want to put their own ideas into it, so they need some guidance on the specifics from the platform they choose. I still don’t understand about how trackbacks and pingbacks work!
Continue reading Choosing a Blog Platform