-
Notifications
You must be signed in to change notification settings - Fork 0
/
wysiwyg-formats.php
57 lines (47 loc) · 1.23 KB
/
wysiwyg-formats.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
<?php
/*
Plugin Name: WYSIWYG Formats
Description: Creates "Formats" dropdown in the WYSIWYG toolbar for site-specific body elements.
Version: 1.0
Author: John Spellman
*/
if (!defined('ABSPATH')) exit;
function wpb_mce_buttons_2($buttons) {
array_unshift($buttons, 'styleselect');
return $buttons;
}
add_filter('mce_buttons_2', 'wpb_mce_buttons_2');
/*
* Callback function to filter the MCE settings
*/
function my_mce_before_init_insert_formats( $init_array ) {
// Define the style_formats array
$style_formats = array(
// Each array child is a format with it's own settings
// Add new elements/classes below
array(
'title' => 'H2 Block Title',
'block' => 'h2',
'classes' => 'block-title',
'exact' => true,
),
array(
'title' => 'Button Link',
'block' => 'a',
'classes' => 'button-link',
'exact' => true,
),
array(
'title' => 'Arrow Tall',
'block' => 'a',
'classes' => 'arrow-tall',
'exact' => true,
),
);
// Insert the array, JSON ENCODED, into 'style_formats'
$init_array['style_formats'] = json_encode( $style_formats );
return $init_array;
}
// Attach callback to 'tiny_mce_before_init'
add_filter( 'tiny_mce_before_init', 'my_mce_before_init_insert_formats' );
?>