Language changing quicktag for WordPress

I’ve modified my quicktags.js to include a button for fast adding of <span lang="language of choice">...</span> pairs. Gotta keep those 0.03 voice browser users happy, you know! (All right, I pulled that figure out of my hat. Truth is, I don’t know if any of my blogs have any readers using text-to-speech synthesizers. But I’m opting on the safe side and trying to make most of my content accessible for such users by tagging it with the appropriate lang= parameters.)

I was hoping to whip these modifications up into a plugin to be dropped into any modern WordPress installation, but it seems that documentation on how to make plugins add quicktags is non-existent, and I couldn’t make it work on my own. Every plugin author seems to have their own way of doing it and yet I was unable to find anything that would work for me.

So I’ll have to settle for making my changes to quicktags.js known here.

I begin by adding these lines into quicktags.js:

edButtons[edButtons.length] =
new edButton('ed_lang'
,'lang='
,''
,'</span>'
,'l'
);

function edSpanLang(myField, i) {
	langSelect = document.getElementById('edLang');
	langLang = langSelect.options[langSelect.selectedIndex].value;
	if (!edCheckOpenTags(i)) {
		edButtons[i].tagStart = '<span lang="' + langLang + '">';
		edInsertTag(myField, i);
	}
	else {
		edInsertTag(myField, i);
	}
}

Next, I change the edShowButton() function to include one additional else if -branch, like so:

else if (button.id == 'ed_lang') {
  document.write('<input type="button" id="' + button.id
  + '" accesskey="' + button.access + '" class="ed_button"
  onclick="edSpanLang(edCanvas, ' + i + ');" value="'
  + button.display + '" />\\n<form>\\n<select id="edLang">\\n<option
  value="en">en: English</option>\\n<option value="de">de:
  German</option>\\n<option value="fi">fi: Finnish</option>\\n<option
  value="sv">sv: Swedish</option>\\n</select>\\n</form>');
}

(Sheesh, it's a pain to try and format code inside a WordPress post. I tried to make sure there are no typos but if something breaks after applying these changes, I probably missed one or two. You'll have to use your own eyes and skillz in that case.)

Adding further languages into the drop down list is as easy as adding another <option value="your two-letter language code of choice">your two-letter language code again: your plain English language name</option>\n pair in between the <form>...</form> block. As a Finn, I find the four languages listed in my example to be sufficient for most cases. (Now that I've said it, I realize that I should add French there as well. There's at least as much use for it as there is for German.)

Here's my current (24.5.2007 22.6.2007 19.10.2007) quicktags.js for reference. Note that it has three buttons for my Post Changelog Plugin: history, edit and at. Without the plugin, the code they produce will not work.

WordPress quicktags: removing 'lookup'

The only relevant thread I found on WordPress support forums about this was closed to replies, so I’ll make a note of what I found here: removing the ‘lookup’ quicktag button from the post editor can be achieved by commenting out line 196 (WP 2.2) of quicktags.js (which is in wp-includes/js/), like this:

/* document.write('<input type="button" id="ed_spell" class="ed_button" onclick="edSpell(edCanvas);" title="' + quicktagsL10n.dictionaryLookup + '" value="' + quicktagsL10n.lookup + '" />'); */

No need to edit anything else, although I suppose you could comment out the edSpell function too, since after the change there should be no use for it.

Note that at least in my Firefox/Win I had to clean up the cache before reloading the post editor would reflect the change.

WordPress 2.1: wp_get_links and wp_list_bookmarks

“The way Links used to work is that all links had a “before” and “after” bit associated with them. wp_get_links respected that, and if you had li and /li in the Links manager for those links, then that’s what got output.

But Links aren’t the same as they used to be anymore. So wp_get_links no longer works quite the same way. While it’s not actually deprecated, it probably should be since it just ends up using the new “bookmarks” functions anyway.

I’d switch to wp_list_bookmarks to do what you need it to do.”

Otto42@WP Support Forum

Took me a while to find out how to make wp_list_bookmarks work as wp_get_links did. Firstly, upgrading to 2.1 seems to change the link categories’ ids, so they had to be looked up. In the end I came up with wp_list_bookmarks("category=43&categorize=0&title_li=&show_images=0"); – the title_li bit was the most difficult to understand (my initial attempts with double single quotes caused only weird output).