Is there a plugin to insert pre-defined link into editor?

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!

Related posts

Leave a Reply

2 comments

  1. 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') ) {
         return;
       }
    
       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() {
                         ed.selection.setContent('http://mylink.com');
    
                    }
                });
            },
            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.

  2. 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.