Topic: https://brettterpstra.com/2010/04/17/adding-a-tinymce-button/
hide preview

What's next? verify your email address for reply notifications!

Matt Hull 13y, 357d ago

Actually, looking at this I have managed to add a pdf button to the tinymce, but I would like to attach it to this plugin: http://wordpress.org/extend... in order to write the shortcode around the link like this: [gview file="http://url.to/file.pdf"] is that possible? how could that be done?

remark link
hide preview

What's next? verify your email address for reply notifications!

Brett 13y, 354d ago

Yep, just change the line in editor.js to this:

 ed.execCommand('mceInsertContent', false, '[gview file="'+m[1]+'"]');
hide preview

What's next? verify your email address for reply notifications!

Matt Hull 13y, 357d ago

Do you think a similiar tinymce button could be added for a google pdf viewer script like this one: http://davismetro.com/gde/u... or indeed a shortcode like this: http://wpsnipp.com/index.ph...

How could this be done?

hide preview

What's next? verify your email address for reply notifications!

James 14y, 19d ago

Thanks for the guide, helped me a lot. I had to modify the JavaScript slightly to work with my own shortcode I had created. Thanks again!

hide preview

What's next? verify your email address for reply notifications!

Stan 14y, 19d ago

You saved my day! THANKS A LOT!!!!

hide preview

What's next? verify your email address for reply notifications!

Aaron W. Herd 14y, 31d ago

This has been incredibly helpful. I was having the hardest time getting a custom TinyMCE button to work, but I was able to figure it out from your example. Thanks!

hide preview

What's next? verify your email address for reply notifications!

Dennis 14y, 108d ago

Thanks a lot for sharing this, it was very useful for me - exactly what I was looking for :) Keep it up!

hide preview

What's next? verify your email address for reply notifications!

Frankie Jarrett 14y, 123d ago

Excellent tut! I plan to use something like this in my next theme :) Thanks, Brett

hide preview

What's next? verify your email address for reply notifications!

Dion GeBorde 14y, 136d ago

Wow, thanks for the phenomenally fast response.

Seeing your response, going to the pages you recommended, and re-reading what you wrote in the post really helped me to gain a better understanding of what I missed. I was thinking you were skipping a necessary step about creating buttons from shortcodes. I'll restate what I understand now, just to make sure I've got it:

You were saying that rather than teach us in this post how to create a quicktag button in the HTML editor -- because we could just type in what we needed directly with a shortcode -- you were going to focus on creating a button in the Visual Editor, because that's what the technologically challenged most need. Right? OK, think I got it. Thanks.

With regard to TinyMCE Advanced, going through the instructions, I couldn't see where it specifically allows me to add my own, but as you mentioned, it probably won't interfere, either.

Thanks again, Brett.

hide preview

What's next? verify your email address for reply notifications!

Dion GeBorde 14y, 136d ago

Hey Brett, really dig this nearly-complete treatment, because I'm looking to do just this kind of thing in the next few days.

I'm a complete php/js newbie who's been cobbling together my programming skills in dancing through the WP codex and blogs like yours in just the past week or so, though I've seen precious few that detail it like this. So, I've got a couple questions/clarifications/requests, if you're not sleeping and not tied up with other projects. ;-)

<ol>
<li>

You mentioned above that you essentially skipped the "Adding a button to the "quick tags" in the HTML editor" part because it's a cinch. I've never heard of this. Any tips where I can find out more?

</li>
<li>

I'm using the plugin TinyMCE Advanced. Does this support -- or complicate -- what you've presented here? I've only gotten exposure to TinyMCE in the past few days, so don't know if it's best to use a plugin or if there's a better way to do it.

</li>
</ol>

Thanks man.

remark link
hide preview

What's next? verify your email address for reply notifications!

btadmin 14y, 136d ago

For QuickTags I just found AddQuickTag and set it up to make Markdown links. Worked like a charm in WP 3.0.1. Just FYI.

hide preview

What's next? verify your email address for reply notifications!

btadmin 14y, 136d ago

You might check this out for QuickTags, though I have no idea how it plays with WP 3:

http://rmnl.net/wp-addquicktag-plugin-for-adding-quicktags/

Also, just google for "Adding quicktag buttons to wordpress" and you'll find it. It's a pretty simple javascript function you can just keep extending, but you'll want to do it through external hooks, so skip the tutorials that tell you to modify files inside of wp-include.

I haven't used TinyMCE Advanced for a long time, I can't remember if it has the ability to add its own buttons or not. Either way, it shouldn't conflict. The method here is a standard method of extending the editor and should play nicely with any plugin which implements that method.

hide preview

What's next? verify your email address for reply notifications!

mattonomics 14y, 141d ago

Thank you SO MUCH! This kind of info needs to be in the WP Codex.

hide preview

What's next? verify your email address for reply notifications!

sara 14y, 182d ago

Hi Brett,

This is a unrelated question and I hope you don't mind me asking it here but I am struggling to add TinyMCE editor to an existing plugin I am using. I have research it for quite some time and tried many different approaches but I can't seem to get it working :-(

Would you have any idea how I go about it? I am quite new to wordpress so still learning.

Thanks

remark link
hide preview

What's next? verify your email address for reply notifications!

btadmin 14y, 182d ago

I'm not sure what you mean… adding TinyMCE to a plugin, or did you mean vice versa? If you want to get TinyMCE working in a setup screen or within a plugin, it should be fairly straightforward JavaScript used to replace the textarea on load.

hide preview

What's next? verify your email address for reply notifications!

Matt Cassarino 14y, 185d ago

Nice! Would be really slick if this were all wrapped up nicely in a plugin. Any possibility of that in the near future?

remark link
hide preview

What's next? verify your email address for reply notifications!

btadmin 14y, 185d ago

Possibly, if I find myself up late at night, unable to sleep and without other pressing projects (that's when most of this stuff gets written :). I'll see what I can do.

remark link parent
hide preview

What's next? verify your email address for reply notifications!

Matt Cassarino 14y, 180d ago

Actually, Viper's Video Quicktags does a really good job of this.
http://wordpress.org/extend...

hide preview

What's next? verify your email address for reply notifications!

Eimantas 14y, 224d ago

Same situation as Robert's here(Wordpress 3.0)

hide preview

What's next? verify your email address for reply notifications!

Robert 14y, 239d ago

I'll echo the other users' comments above -- thanks a lot for taking the time to document this process in such a thorough and helpful way! It takes long enough to figure this stuff out for oneself, and the community out here appreciates the added effort you put in.

Unfortunately on my part, I went through and followed the tutorial step by step, but for the life of me I can't get the button to appear. I've compared it with the code from other apps that do get the button to appear, and it appears to make exactly the same calls, etc. -- but it still won't work for me for some reason.

I was curious, and dropped in your code line for line -- and still no button.

I've tried everything I can think of for debugging, and am at a dead end -- do you have any thoughts of what else I should look for? (Note - I'm trying to add a button so that the admin can paste in a lengthy shortcode automatically.)

Thanks again for the tutorial, and thanks in advance for any suggestions you might have.

Robert

remark link
hide preview

What's next? verify your email address for reply notifications!

btadmin 14y, 239d ago

I also haven't tested this with Wordpress 3.0 yet, but will be upgrading her site soon and can update here if that turns out to be the problem.

hide preview

What's next? verify your email address for reply notifications!

btadmin 14y, 239d ago

Anything I would suggest is already in the code above. If you're adding the custom php functions to your functions.php file and putting the JS in editor_plugin.js (and have the matching png file for the button), I don't know why it wouldn't show up for you.

Do you have other custom functions that you know are working in functions.php? You could also throw a console.log statement into the editor js and see if it was being called appropriately…

hide preview

What's next? verify your email address for reply notifications!

Ash Blue 14y, 273d ago

Thanks man, this is exactly what I was looking for. This information is scattered everywhere on the WordPress docs so its nice to find it neatly organized/explained here.

remark link
hide preview

What's next? verify your email address for reply notifications!

ttscoff 14y, 273d ago

Makes my day when my toils and troubles help somebody else out, makes the hours seem more worthwhile in the long run :). Thanks for letting me know.

hide preview

What's next? verify your email address for reply notifications!

jeremy clarke 14y, 303d ago

Thanks for taking the time to write up such a thorough description of the process, though I'm not sure its as easy as you say ;)

FWIW, I created a WordPress Idea to add a functions.php function that would be a wrapper for this kind of logic, so non-js coders could easily add buttons with just one function call: http://wordpress.org/extend...

What I need is a button that behaves the way the bold and italic ones do, managing opening/closing intelligently like the quicktags in the html view do. If I don't find something more specifically appropriate i'll take a stab with your code and see if I can get it to work.

hide preview

What's next? verify your email address for reply notifications!

John 14y, 307d ago

Where would you install this to? I want to make a simple button that adds a Back to top graphical link. but I don't know where to put the directory.

remark link
hide preview

What's next? verify your email address for reply notifications!

ttscoff 14y, 307d ago

This tutorial is designed to go into your theme's directory, and uses the functions.php file that you'll find there. Do you plan to have just one "back to top" button per post/page? If that's the case, you might want to consider adding one automatically after the content using a hook or by just adding it to the template. If you have multiple buttons, though, and you have an anchor to jump to, then that would be a cool button to add!

hide preview

What's next? verify your email address for reply notifications!