Ever since WordPress introduced quicktags, people have been wanting to customize them. Naturally, a lot of tutorials popped up, demonstrating how to do this. The problem is that all of them require that you edit quicktags.js, a file in WordPress.

But it doesn’t have to be that way now, since newer versions of WP have a script loading API. So here’s a better way to do it, without modifying any core files:

First, we make a basic plugin file, where we tell WP to load some javascript, right after loading the quicktags script:

<?php
/*
Plugin Name: My Custom Quicktags
Version: 1.0
*/
 
add_action('admin_print_scripts', 'my_custom_quicktags');
function my_custom_quicktags() {
	wp_enqueue_script(
		'my_custom_quicktags',
		plugin_dir_url(__FILE__) . 'my-custom-quicktags.js',
		array('quicktags')
	);
}

Now, instead of modifying quicktags.js, we add our quicktag code in a separate file:

edButtons[edButtons.length] =
new edButton('sup'
,'sup'
,'<sup>'
,'</sup>'
,''
);

Feel free to modify this to suit your needs.

The benefit of this method is that when you upgrade WordPress, your quicktag(s) will still be there.

I’ve made a .zip with these two files, which you can download and install as a regular plugin. It has been tested on WordPress 2.8.1 and 2.7.1.

Download

I’d love to know what quicktags you make with this tutorial, so feel free to share in the comments.

Update

It seems someone has taken this a step further, with the Post Edit Buttons plugin. More power to him :)

Reactions (2)

Comments (5)

  • Erik Ronström says:

    Great, thanks!

    I was hoping I would not have to go edit quicktags.js directly, and now I know how to :)

  • Erik Ronström says:

    Oh, BTW there is a subtle error in your code, it should be plugin_dir_url (not plugins_dir_url)

  • Toby says:

    I just tried activating your plugin, and I received the following error:

    Plugin could not be activated because it triggered a fatal error.

    Any thoughts on why I am getting this error?

    I am using Wordpress 2.9.1.

    • scribu says:

      Would be really useful if you posted the actual error text.

      Try using the Post Edit Buttons plugin mentioned in the post, instead. If you experience problems with that one, contact it’s author.

Respond / add a comment


Subscribe without commenting