How to add a new tab to page editor

The question:

Anyone knows how to achieve this?

enter image description here

It has something to do with meta boxes, but I just can’t figure out the proper syntax.

The Solutions:

Below are the methods you can try. The first solution is probably the best. Try others if the first one doesn’t work. Senior developers aren’t just copying/pasting – they read the methods carefully & apply them wisely to each case.

Method 1

I remembered that once I done this, yesterday I found where, but that code was… bad.
So today I little improved it and I’m going to share. Before I want to explain what I do.

First of all, there are 3 main things to do:

  1. Add the tab title beside the standard 2
  2. Add something to the content of the tab
  3. Make the content appear when our tab title is clicked, and disapper when standard tab titles are clicked

Most of things need js so we also need to enqueje js in the right pages (post.php and post-new.php).

1st point can’t be done via PHP, because the markup for those buttons are directly echoed from wp_editor function, without be processed by any filter.
So only chance is add them via javascript.

2nd point, can be easily done via PHP, using a function hooking the_editor filter.

3rd point again is done via javascript.

For all the code I created a simple plugin containing 3 file:

  • gmet.php – the main plugin file
  • gmet.js – the file containing javascript
  • gmet-content.php – this file contain the tab content

I created anotther file for the tab content in this way is easy to customize it, without digging into code.


<?php namespace GMET;
 * Plugin Name: GM Editor Tab
 * Author: Giuseppe Mazzapica
 * Author URI:
 * Text Domain: gmet

add_action('admin_init', 'GMETinit'); 

function init() {
  load_plugin_textdomain( 'gmet', false, dirname( plugin_basename( __FILE__ ) ) );
  add_action('admin_enqueue_scripts', 'GMETscripts');
  add_filter('the_editor', 'GMETcontent');

function scripts( $page ) {
  if ( $page === 'post.php' || $page === 'post-new.php' ) {
    $custom_css = " { 
      border-color: #ccc #ccc #f4f4f4; background-color: #f4f4f4; color: #555;
    wp_add_inline_style( 'colors', $custom_css );
    wp_enqueue_script('gmet', plugins_url('/gmet.js', __FILE__ ) );
    wp_localize_script( 'gmet', 'gmetData', array(
      'tabTitle' => __('My Custom Tab', 'gmet')
    ) );

function content( $content ) {
  preg_match("/<textarea[^>]*id=["']([^"']+)"/", $content, $matches);
  $id = $matches[1];
  // only for main content
  if( $id !== "content" ) return $content;
  include( plugin_dir_path( __FILE__ ) . 'gmet-content.php' );
  return $content . ob_get_clean();

There are only 3 functions: the first setup the hooks, the second add the javascript in the page, the third is responsible to add the content on the tab page.


(function($) {

  $(document).ready(function() {
    var $bar = $('<div></div>');
    $wrap = $('#gmet_content_wrap');
    $wrap.children().css('padding', '5px 15px');
    $('#wp-content-editor-tools #content-html').before(
      '<a id="content-gmet" class="wp-switch-editor">' + gmetData.tabTitle + '</a>'

  $(document).on('click', '#content-gmet', function(e) {
    var id = 'content';
    var ed = tinyMCE.get(id);
    var dom = tinymce.DOM;
    $('#wp-content-editor-container, #post-status-info').hide();
    dom.removeClass('wp-content-wrap', 'html-active');
    dom.removeClass('wp-content-wrap', 'tmce-active');

  $(document).on('click', '#content-tmce, #content-html', function(e) {
    $('#wp-content-editor-container, #post-status-info').show();


Again 3 tasks: on document ready I setup some css and, most important, I add our tab title markup to the editor. Second task run when user click on our tab title: the standard editor is hidden an our content is shown. To hidden standard editor I copyed and pasted som code from wp-admin/js/editor.js. Last task is the easiest, when standard tab titles are clicked I hide our tab content and remove the class ‘active’ that from tab title.


<div id="gmet_content_wrap" class="wp-editor-container">
  <!-- Everything you want to output should go inside this div -->
  <h3>Hi there</h3>
    <input type="text" class="regular-text" name="gmet_text" placeholder="Example" />
   <textarea name="gmet_textarea" cols="100" id="gmet_textarea" rows="10"></textarea>

This file contain what is shown in aour tab. This is only an example, customize it as you want, only remember to add everything iside the wrapper div.

Now, just create a folder inside your plugins directory, save all 3 files inside it, and then go to your dasboard and activate the plugin.

All files are available as Gist here.

Method 2

This isn’t going to be easy to do. This is hard-coded into the core, and has nothing to do with meta boxes.

If you inspect the HTML for these tabs, you can see some classes like wp-switch-editor switch-html and switch-tmce. If you search through the core code for these classes, you could find out where its creating these tabs.

The hardest part would be to dissect the JavaScript that actually switches it, and add support for your new tab.

All methods was sourced from or, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

Leave a Comment