Tutorial: Adding Buttons To The Post Editor

For some of you this may have never even crossed their minds, but have you ever wondered how to add your own WordPress Post Editor buttons? (When I say the WordPress Post Editor, I’m referring to the area where you write your posts).

Well, yesterday it dawned on me that it would make my life a lot easier if I could, with 1 click of a button, add in <h1> and <h2> tags into my posts. Wouldn’t that be awesome? Hell yeah dude!

Alright, so with that said, I’ll be running through some steps with you to get your WordPress Post Editor (in Code view) to look like this:

This is going to be fairly easy, so let’s get started!

Step 1: Locating The File

Let’s begin by opening up our FTP or whatever you use to edit your files. Locate where WordPress is installed and go to:

/wp-includes/js/quicktags.js

Now at around line 36, you should see something that looks like this:

edButtons[edButtons.length] =
new edButton(’ed_strong’
,’b’
,’<strong>’
,’</strong>’
,’b’
);

That code above is the code for a single button, specifically the Bold button. Pretty simple right?

Step 2: Adding Your Own Button

(Before doing any editing, please make sure you have a back up of this file, just incase you make any mistakes)

Now that we know what the button source code looks like, we can simple re-write it to make one of your own. Below is the source code for my <h1> button:

edButtons[edButtons.length] =
new edButton(’ed_more’
,’h1′
,’<h1>’
,’</h1>’
,’h’
,-1
);

Let’s break down the code to get a better understanding.

edButtons[edButtons.length] =
new edButton(’ed_more’

This is basically defining the code as a button.

,’h1′

This will be the name of the button that will display in your post editor.

‘<h1>’

This is the first tag that will insert when the button is clicked. This is also the opening h1 tag.

,’</h1>’

This is the last tag that will insert when the button is clicked again. This is also the closing h1 tag.

,’h’

This is the back end name of the button.

,-1
);

This is basically just closing up the button source code (do not edit this).

Make sure you include every piece of code and space them accordingly in the file, like the others. Easy huh? You can also add up to a couple of buttons and different ones to fit your purposes.

Step 3: Saving And Using

Alright, well you guessed it! Save that file and head over to WP-Admin > Write > New Post and check out your cool new buttons!

If you don’t see the buttons or something looks totally messed up, retrieve your back up and follow the tutorial again slowly.

Step 4: Final Words

Well this was my first tutorial on WPCandy, so I hope you enjoyed it and got the best of it!

41 Responses to “Tutorial: Adding Buttons To The Post Editor”

Travis
Posted on December 4th, 2007 at 8:33 PM

Always wondered how to do this. Excellent tutorial Michael.

Michael Castilla
Posted on December 4th, 2007 at 8:39 PM

Thanks for stopping by Travis! And thanks for the comment as well. Glad you enjoyed it.

hellyeahdude.com
Posted on December 4th, 2007 at 8:40 PM

That was cute.

Brady
Posted on December 4th, 2007 at 9:39 PM

Woot, the newbs learn some more.

david
Posted on December 4th, 2007 at 10:41 PM

There’s a plugin that does this pretty simply:

http://roel.meurders.nl/wordpress-plugins/wp-addquicktag-plugin-for-adding-quicktags/

I’ve been using it for a while, and it works great.

Michael Castilla
Posted on December 4th, 2007 at 10:59 PM

Hey David, thanks for stopping by WPCandy and sharing that plugin with us. I’m gonna go cry myself to sleep now.

Brady
Posted on December 4th, 2007 at 11:00 PM

Now now Mike..

Justin Tadlock
Posted on December 5th, 2007 at 12:04 AM

Cool tutorial. I would use it, but I’m so used to typing every tag in myself now that I don’t think I’ll ever use those buttons. I can type much faster than clicking the button. Nevertheless, I’m sure this will help many people.

Ali Salem
Posted on December 5th, 2007 at 12:05 AM

Thanks dude! That’s one cool tip. :)

Andrewy
Posted on December 5th, 2007 at 12:19 AM

Thanks Mike,

I had thought of doing it but never go round to it. I think I might well put my standard opening tags into one, in a one-click style, so my header and intro para are just inserted as a whole.

Aaron
Posted on December 5th, 2007 at 6:17 AM

Thanks for the tip Michael.

Michael Castilla
Posted on December 5th, 2007 at 7:28 AM

Thanks guys and your welcome! Glad I could help you all.

Darren Hoyt
Posted on December 5th, 2007 at 11:14 PM

Nice! I’m trying to do the same thing currently so that “target=blank” is an attribute for every anchor tag in the WYSIWYG.

Armen
Posted on December 6th, 2007 at 12:22 AM

Really nice work here, Michael. I had no idea about this.

Stumbled!

Frank
Posted on December 6th, 2007 at 5:43 AM

http://wordpress.org/extend/plugins/addquicktag/

The actual version, works under WP 2.3 and have import- and export-function.
I hope you enjoy this easy way for adding buttons to the editor.
With best regards Frank

Michael Castilla
Posted on December 6th, 2007 at 3:24 PM

@Darren: Oh that could come in handy! Were you able to accomplish that with this tutorial?

@Armen: Thanks bro!

@Frank: Hehe yeah I’ve realized there are a few plugins that automatically do this, so this is for the do-it-yourself kind of people!

CP
Posted on January 2nd, 2008 at 6:29 PM

Thanks to everyone who commented and thanks for writing this article. I was in search of this today and you guys came to the rescue. Thanks.

Mosey
Posted on January 13th, 2008 at 11:16 AM

Thanks for this post! :D I’ve always wanted to add an acronym button to the editor bar since the standard editor really works well for me, excluding this particular tag. Whilst I see the perks of using a plugin to manage the tags, it’s probably most suitable for people who need loads of tags. For this one acronymn tag, I’ll definitely be editing the file itself, so thank you for the tutorial! :)

Michael Castilla
Posted on January 13th, 2008 at 12:55 PM

@Mosey: No problem! I’m glad it is of use to you!

Hannah
Posted on January 21st, 2008 at 7:25 AM

Thanks for this! I’ve always wanted to do this and the plug-ins I’ve tried don’t work.

Jeffro2pt0
Posted on January 21st, 2008 at 3:35 PM

Awesome tutorial folks. I used it to give the H1 and H2 headings their own button. It’s saved me quite a few seconds :)

Andy
Posted on February 26th, 2008 at 6:32 PM

Thanks for this nice tutorial!
As I only needed two buttons this worked as good for me as installing another plugin :)

Roland
Posted on August 17th, 2008 at 7:36 PM

I know this is an older tutorial, but is there an easy way to also add an image to the button when using the ‘visual editor’ in WP2.6? I got a button added using the tutorial, but it only shows in the HTML-view of the editor.

antonio
Posted on November 4th, 2008 at 9:46 AM

good post

kalpesh gamit
Posted on November 7th, 2008 at 12:23 AM

good post

Kaushik
Posted on December 30th, 2008 at 1:47 AM

neat stuff! I’m going to go the plugin way though ;) , but always cool to know the hands-on way of getting this stuff done.

Trackbacks
Leave a Reply