• 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!

    Post Revisions:

    Posted December 4, 2007

29 comments

  1. Travis said:

    Always wondered how to do this. Excellent tutorial Michael.

    on December 4, 2007 at 8:33 pm Reply

  2. Michael Castilla said:

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

    on December 4, 2007 at 8:39 pm Reply

  3. hellyeahdude.com said:

    That was cute.

    on December 4, 2007 at 8:40 pm Reply

  4. Brady said:

    Woot, the newbs learn some more.

    on December 4, 2007 at 9:39 pm Reply

  5. david said:

    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.

    on December 4, 2007 at 10:41 pm Reply

  6. Michael Castilla said:

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

    on December 4, 2007 at 10:59 pm Reply

  7. Brady said:

    Now now Mike..

    on December 4, 2007 at 11:00 pm Reply

  8. Justin Tadlock said:

    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.

    on December 5, 2007 at 12:04 am Reply

  9. Ali Salem said:

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

    on December 5, 2007 at 12:05 am Reply

  10. Andrewy said:

    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.

    on December 5, 2007 at 12:19 am Reply

  11. Aaron said:

    Thanks for the tip Michael.

    on December 5, 2007 at 6:17 am Reply

  12. Michael Castilla said:

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

    on December 5, 2007 at 7:28 am Reply

  13. Darren Hoyt said:

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

    on December 5, 2007 at 11:14 pm Reply

  14. Armen said:

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

    Stumbled!

    on December 6, 2007 at 12:22 am Reply

  15. Frank said:

    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

    on December 6, 2007 at 5:43 am Reply

  16. Michael Castilla said:

    @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!

    on December 6, 2007 at 3:24 pm Reply

  17. CP said:

    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.

    on January 2, 2008 at 6:29 pm Reply

  18. Mosey said:

    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! :)

    on January 13, 2008 at 11:16 am Reply

  19. Michael Castilla said:

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

    on January 13, 2008 at 12:55 pm Reply

  20. Hannah said:

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

    on January 21, 2008 at 7:25 am Reply

  21. Jeffro2pt0 said:

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

    on January 21, 2008 at 3:35 pm Reply

  22. Andy said:

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

    on February 26, 2008 at 6:32 pm Reply

  23. Roland said:

    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.

    on August 17, 2008 at 7:36 pm Reply

  24. antonio said:

    good post

    on November 4, 2008 at 9:46 am Reply

  25. kalpesh gamit said:

    good post

    on November 7, 2008 at 12:23 am Reply

  26. Kaushik said:

    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.

    on December 30, 2008 at 1:47 am Reply

  27. neel said:

    Excellent post. I will like to add butons in my plugin..

    on January 2, 2010 at 2:31 am Reply

  28. 9WordpressTemplate said:

    Good tut, thanks.

    on April 1, 2010 at 1:12 pm Reply

  29. Nick said:

    Hi, this doesn’t work for 2.9 version. Moreover, you should indent quicktags.js before editing it.

    on July 6, 2010 at 3:30 am Reply


RSS feed for comments on this post.

Leave a comment

Trackbacks on this post

  1. Wp Wordpress » Blog Archive » Customizing Your WYSIWYG Editor Buttons in Wordpress

    [...] gave a nice tutorial this week on how to add and edit the behaviors of WYSIWYG buttons in WordPress. This inspired me to [...]

  2. Buffer Dump 19DEC07 « Feet up, eyes closed, head back

    [...] “Customizing Your WYSIWYG Editor Buttons in WordPress“, which points to this lovely tutorial at WPCandy: “Tutorial: Adding Buttons To The Post Editor“ [...]

  3. Hack: Adding Buttons To The WordPress Write Panel

    [...] people looking for a way to do this, I recommend you read the tutorial written on WPCandy called Adding Buttons To The Post Editor. Michael has taken the time to spell out each individual step so that someone without any coding [...]

  4. CreativeBurst.ORG » Hacking Wordpress

    [...] Adding Buttons to the Post Editor [...]

  5. Add Buttons To Visual Editor » Jeffro2pt0.com

    [...] WPCandy has an awesome tutorial online which takes you through the motions of creating and then adding your own custom button to the text editor. For instance, when I want to use the H2 tag, I have to click on the button which brings down the advanced options and then select H2 Heading from the drop down box. Using this tutorial, I have created a button specifically for H2 so I no longer need to browse through the advanced buttons area. [...]

  6. Ajout de boutons dans l’éditeur de billet | Khayspace

    [...] à WP-CANDY qui m’a donné envie de faire une version française de son billet. Personnellement, je préfèrerais rajouter des boutons à des éditeurs plus évolués mais [...]

  7. WordPress Weekly Episode 3 » Jeffro2pt0.com

    [...] Add Buttons To Text Editor – WP Candy published an awesome tutorial which highlights how to add custom buttons/functions to your visual text editor. For instance, I’ve managed to add a H1 and H2 button to my visual text editor so I no longer need to access the dropdown menu. [...]

  8. 25 hacks para dinamizar seu Wordpress! — Bytes a Go-go!

    [...] Adicionar novo botões na área onde escreve artigos. Gostei desse. =D [...]

  9. Moewes.com » links for 2008-01-26

    [...] WPCandy » Tutorial: Adding Buttons To The Post Editor [...]

  10. 20 Places For Wordpress Hacks | Index Blog

    [...] Add Buttons To The Post Editor, Tutorial that shows how to add new buttons to the post editor. [...]

  11. WordPress Weekly Episode 3 | Jeffro2pt0

    [...] – Add Buttons To Text Editor – WP Candy published an awesome tutorial which highlights how to add custom buttons/functions to [...]

  12. Edit the ‘Link’ Button in Wordpress | Mike Haydon

    [...] to edit any of the other buttons, or add your own, such as a <h1> button, there is an excellent tutorial on editing wordpress buttons. Popularity: 1% [?]If you’re new here, you may want to subscribe to my RSS feed. Thanks for [...]

  13. Adding Your Own Buttons to the WordPress Editor | Flash Barracks Blog

    [...] create posts) Well I have, so I started searching around the web for a way to do that and I found this. You can either go look at that site or you can just keep reading because I will be explaining the [...]

  14. new/ stuff » edit your Wordpress buttons/ post in HTML view

    [...] for the guidance, wpcandy December 16th, 2008 | found in how-to, web page one | | page [...]

  15. Editöre Yeni Düğmeler Ekliyoruz · Yakup Gövler'in Not Defteri

    [...] WPCandy (Buradaki yazı hatalıydı, ben düzelterek yazdım) Yazıyı Paylaş: Aşağıdaki simgeler [...]

TrackBack URL