Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save robneu/7b2877e69bb9fa9620a9 to your computer and use it in GitHub Desktop.
Save robneu/7b2877e69bb9fa9620a9 to your computer and use it in GitHub Desktop.
<?php
/**
* Plugin Name: Remove H1 Format
* Plugin URI: http://calliaweb.co.uk/modify-tinymce-editor/
* Description: A simple plugin to remove the H1 format from the WordPress TinyMCE editor.
* Version: 0.0.1
* Author: Jo Waltham
* Author URI: http://calliaweb.co.uk/
* License: GPL-2.0+
* License URI: http://www.gnu.org/licenses/gpl-2.0.html
*/
// Exit if accessed directly
defined( 'WPINC' ) or die;
if ( ! class_exists( 'Remove_H1_Format' ) ) :
class Remove_H1_Format {
function run() {
add_filter( 'tiny_mce_before_init', array( $this, 'tiny_mce_remove_h1' ) );
}
/*
* Modify TinyMCE editor to remove H1.
*/
public static function tiny_mce_remove_h1( $init ) {
//* Allow developers to conditionally short-circuit the plugin.
$pre = apply_filters( 'tiny_mce_remove_h1', false );
//* If the plugin has been short circuited, do nothing.
if ( ! empty( $pre ) ) {
return $init;
}
// Add block format elements you want to show in dropdown
$init['block_formats'] = 'Paragraph=p;Heading 2=h2;Heading 3=h3;Heading 4=h4;Heading 5=h5;Heading 6=h6;Address=address;Pre=pre';
return $init;
}
}
endif; // End class exists check.
//* Handy function for grabbing the plugin instance
function jw_remove_h1_format() {
$plugin = new Remove_H1_Format;
return $plugin;
}
//* Get the plugin running.
jw_remove_h1_format()->run();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment