Created
January 15, 2019 20:22
-
-
Save jonbrockett/b2c85fe04ab069c5570527b8319d2c15 to your computer and use it in GitHub Desktop.
TinyMCE Custom Styles
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** TinyMCE Styles Changes **/ | |
require_once( 'library/tinymce-styles.php' ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Foundation Styles for TinyMCE | |
*/ | |
// Callback function to insert 'styleselect' into the $buttons array | |
function my_mce_buttons_2( $buttons ) { | |
array_unshift( $buttons, 'styleselect' ); | |
return $buttons; | |
} | |
// Register our callback to the appropriate filter | |
add_filter( 'mce_buttons_2', 'my_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 | |
array( | |
'title' => 'Primary Button', | |
'selector' => 'a', | |
'classes' => 'button', | |
), | |
array( | |
'title' => 'Secondary Button', | |
'selector' => 'a', | |
'classes' => 'secondary button', | |
), | |
array( | |
'title' => 'Primary Hollow Button', | |
'selector' => 'a', | |
'classes' => 'hollow button', | |
), | |
array( | |
'title' => 'Secondary Hollow Button', | |
'selector' => 'a', | |
'classes' => 'secondary hollow button', | |
), | |
); | |
// 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' ); | |
/* | |
* Modify TinyMCE editor to remove H1. | |
*/ | |
function tiny_mce_remove_unused_formats($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; | |
} | |
add_filter('tiny_mce_before_init', 'tiny_mce_remove_unused_formats' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment