After searching several hours, I've decided to crowd-source this one. I have a client who uses Wordpress very frequently, they often have to create a link to a certain page for collecting donations - the issue is they always get the link wrong (long story, but they always screw it up!). I've been searching for a plugin or tutorial on how I can add a button to the editor that would automatically add the link to their post - ensuring the link is always correct. As mentioned I searched several hours and was wondering if someone could point me in the right direction. Thanks!

2 Answers 2


You can make a button to the Tinymce editor that adds a pre defined link like this youtube button:

enter image description here

Put this in your functions.php theme file:

// Hook into WordPress
add_action('init', 'mylink_button');

// Create Our Initialization Function
function mylink_button() {

   if ( ! current_user_can('edit_posts') && ! current_user_can('edit_pages') ) {

   if ( get_user_option('rich_editing') == 'true' ) {
     add_filter( 'mce_external_plugins', 'add_plugin' );
     add_filter( 'mce_buttons', 'register_button' );


// Register Our Button
function register_button( $buttons ) {
    array_push( $buttons, "|", "mylink" );
    return $buttons;

// Register Our TinyMCE Plugin
function add_plugin( $plugin_array ) {
    $plugin_array['mylink'] = get_bloginfo( 'template_url' ) . '/link.js';
    return $plugin_array;

And then make a link.js file and put it in your theme root with this in it:

// JavaScript Document
(function() {
    tinymce.create('tinymce.plugins.mylink', {
        init : function(ed, url) {
            ed.addButton('mylink', {
                title : 'My Link',
                image : url+'/mylink.png',
                onclick : function() {

        createControl : function(n, cm) {
            return null;
    tinymce.PluginManager.add('mylink', tinymce.plugins.mylink);

Change http://mylink.com to the link you want to add. Also add a icon called mylink.png in the theme root.

  • Pontius - Excellent post and example code. This is exactly what I was searching for! Thank you! Cheers!
    – BD_Design
    Jul 2, 2012 at 15:07

I don't know what dbx_post_advanced hook is for, but you might be able to use it to do what you want.

static function insert_some_text( $arg1 ) {
   global $post ;

   if( $post->post_name == '' ) {
       $post->post_content = 'Some Hello World' ;
add_action('dbx_post_advanced', 'insert_some_text');

Add this code into your functions.php and modify it. The post_name check you may want to replace with checking the URL for post-new.php.

  • Misunderstood the post and this doesn't answer the question - which is to add a button to the editor. Or the original question didn't mention adding a button? Jun 29, 2012 at 12:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.