Remove specific buttons from wp_editor()

I know there are similar topics with accepted answers but I can’t find what I’m looking for. I want to keep only basic buttons in wp_editor(). I’m using this in an option page to make writing more comfortable.

The problem is the theme adds a huge amount of quicktags I do not want on this specific page. How can I achieve this.

Read More

So far I’ve looked into wp-includes/wp-class-editor.php but the following line does not remove unecessary buttons :

'quicktags' => array('buttons' => 'link,ins,img,close')

:/ Any help would be much appreciated.

EDIT: I’ve tried to modify function given in similar topic with this :

function wpa_47010( $qtInit ) {
global $my_plugin_page;
    $screen = get_current_screen();
      if( $screen->id == $my_plugin_page ) 
          $qtInit['buttons'] = 'link,img,close';
return $qtInit;
}
add_filter('quicktags_settings', 'wpa_47010');

But it does not work !

Related posts

2 comments

  1. If you are using the settings API, you can use exactly the same code for calling wp_editor as you would anywhere else

    I’ve test the code below, it adds a setting section to the reading section, and then adds a field to the section containing a WYSIWYG editor with buttons limited to link, img and close

    // Add a setting to the reading page
     function register_plugin_x_settings() {
        // Add a section to reading settings 
        add_settings_section('plugin_x_setting_section','Plugin X (section caption)','plugin_x_setting_section_callback','reading');
    
            // add setting field
        add_settings_field('plugin_x_setting_wysiwyg', 'WYSIWYG Content', 'plugin_x_setting_wysiwyg_callback', 'reading', 'plugin_x_setting_section');
        register_setting('reading','plugin_x_setting_wysiwyg');
     }
     add_action('admin_init', 'register_plugin_x_settings');
    
     // function to render the section
     function plugin_x_setting_section_callback() {
        echo '<p>Plugin X Settings</p>';
     }
    
    // function to render the setting
    function plugin_x_setting_wysiwyg_callback() {
        // global editor id (not necesary, but we may need it elsewhere)
        global $myPluginEditorID;
        $myPluginEditorID = "myPluginEditorUniqueID";
    
        // settings to pass to wp_editor, disables the upload button, and sets minimal quicktags and turns off tinymce
        $settings = array(
            'media_buttons' => false,
            'quicktags'     => array("buttons"=>"link,img,close"),
            'textarea_name' => "input_{$myPluginEditorID}",
            'tinymce'       => false,
        );
    
        // output the wysiwyg editor
        wp_editor( "Content Here", $myPluginEditorID,$settings);
     }
    
  2. The following code works for me, it adds an options page, and adds a WYSIWYG box to that page, with ONLY 3 quicktags: link, img and close, and nothing else.

    Note, I turned of tinyMCE, and passed a settings array (which contains another array for quicktag settings) to wp_editor.

    By passing in unique id of the textarea field, it will only affect the correct box on your plugin options page

    // add admin page
    function my_admin_add_page() {
        global $my_admin_page;
        $my_admin_page = add_options_page(__('My Admin Page', 'map'), __('My Admin Page', 'map'), 'manage_options', 'map', 'my_admin_page');
    }
    add_action('admin_menu', 'my_admin_add_page');
    
    // render admin page
    function my_admin_page() {
        // global editor id (not necesary, but we may need it elsewhere)
        global $myPluginEditorID;
        $myPluginEditorID = "myPluginEditorUniqueID";
    
        // settings to pass to wp_editor, disables the upload button, and sets minimal quicktags and turns off tinymce
        $settings = array(
            'media_buttons' => false,
            'quicktags'     => array("buttons"=>"link,img,close"),
            'textarea_name' => "input_{$myPluginEditorID}",
            'tinymce'       => false,
        );
    
        // output the wysiwyg editor
        wp_editor( "Content Here", $myPluginEditorID,$settings);
    }
    

Comments are closed.