I noticed that WordPress these days uses a shortcode to define image captions, of the form:
[caption id="" align="aligncenter" width="630" caption="Image title goes here"]<img src="http://domain.com/imgpath/../image.jpg" width="630" height="420" />[/caption]
I’ve recently redone our blog template at Technomadics, and while setting up the new preview template in MarsEdit, thought I’d take a stab at implementing support for captions, too, via some javascript in the template.
I was successful! Here’s how I did it:
Added the following to the “head” section:
<script type="text/javascript"> var prior_content; function watch_for_changes() { var check = function() { var elt = document.getElementById('content'); if ( elt.innerHTML != prior_content ) { elt.innerHTML = apply_filters(elt.innerHTML); prior_content = elt.innerHTML; } setTimeout(check, 100); }; setTimeout(check, 100); } function apply_shortcode(source, name, callback) { return source.replace(new RegExp('\\[' + name + '\\s*([^\\]]*)\\]((.|[\s\n])*?)\\[/' + name + '\\]', 'g'), function(match, paramString, content) { params = new Object(); reg = /([a-z]+)="((:?="[^"]+"|[^"])*)"/gi; while ( (match = reg.exec(paramString)) != null ) { params[match[1]] = match[2]; } return callback(params, content); }); } function apply_filters(html) { html = apply_shortcode(html, "caption", function(args, content) { return '<div '+ 'class="wp-caption ' + (typeof(args.align) != 'undefined' ? args.align : '') + '" '+ 'style="width: ' + args.width + 'px;">' + content + '<p class="wp-caption-text">' + args.caption + '</p></div>'; }); return html; } </script>
…changed to ‘body’ tag to…
<body onload="watch_for_changes();">
…And wrapped a div around the main “#body#, #extended#” content with an id of content:
<div id="content"> #body# #extended# </div>
Basically, it polls the content area for changes, and when triggered, runs it though a filter. The above is extensible, and by adding additional “apply_shortcode” calls from “apply_filters“, more shortcodes can be simulated.
If you have come to this page via the theme credit link in the footer of another site, please
understand that I am just the author of the 


Personalising AddThis’s Tweet Button
AddThis is a quite useful WordPress plugin for adding a host of sharing options to your blog posts.
By default, the “Tweet” button that AddThis provides will append “via @AddThis” to the end of tweets, which seems to me a little uncool, given that it’s your content.
So, here’s a little plugin that lets you specify your own Twitter account name instead of @AddThis.
The principle is simple: AddThis were kind enough to define their own filter for the plugin’s output. The plugin plugs itself into this filter, and makes an adjustment to the Tweet button.
To use it, put
addthis-modifier.phpinto yourwp-content/pluginsfolder, open it up and set your twitter name where indicated. Activate it, and you should be good to go.Download the plugin: AddThis Modifier Plugin
For extra marks: Here’s some code you can use to replace line 14 (the $twittername = … line) to provide a different Twitter account for each post author. Is that not awesome?: