How To Customize wp_editor In WordPress

In this article, we learn about how to customize wp_editor in WordPress.

Here is the syntax:

wp_editor( $text, $id, $arg );
  1. $text(string): Your textarea content.
  2. $id(string): Your textarea id.
  3. $arg(array): your wp editor settings.

Here is some arg list:

  1. wpautop (true | false): If true auto paragraph enable.
  2. media_buttons (true | false): If true media button enable.
  3. textarea_name (string): Name of your textarea.
  4. textarea_rows: Textarea rows.
  5. tabindex: tabindex used for the form field.
  6. editor_css: add your css using <style> tag.
  7. editor_class: add your custom class.
  8. teeny (true | false): If true hide minimal editor.
  9. tinymce (true | false | array ): If false hide visual editor.
  10. quicktags (true | false | array ): If false hide text editor.

Here is some example:

  1. Hide visual editor and hide some text editor button.
    $content = 'Your custom text'; 
    $id = 'thecodehubs_bar_id'; 
    $arg = array( 
      'textarea_name' => 'thecodehubs_bar_text', 
      'tinymce' => false, 
      'quicktags' => array( 
        'buttons' => 'strong,em,link,ul' 
      ) 
    );
    wp_editor( $content, $id, $arg );

    Output: 

  2. hide some visual editor buttons.
    $content = 'Your custom text'; 
    $id = 'thecodehubs_bar_id'; 
    $arg = array( 
      'textarea_name' => 'thecodehubs_bar_text', 
      'tinymce' => array( 
        'toolbar1'=> 'bold,italic,underline,bullist,numlist,link,unlink,forecolor,undo,redo,', 
        'toolbar2'=> '', 
      ) 
    );
    wp_editor( $content, $id, $arg );

    Output:

  3. Hide Media button.
    $content = 'Your custom text';
    $id = 'thecodehubs_bar_id';
    $arg = array(
      'textarea_name' => 'thecodehubs_bar_text',
      'media_buttons' => false,
    );
    wp_editor( $content, $id, $arg );

     

Also, you can create your custom tag in the text editor. For more detail read this article.

Submit a Comment

Your email address will not be published. Required fields are marked *

Subscribe

Select Categories