Last active
October 18, 2016 16:03
-
-
Save chrisvanpatten/56a7880f730b58f70c93 to your computer and use it in GitHub Desktop.
Register custom style formats to TinyMCE in WordPress
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 | |
/** | |
* custom_tinymce | |
*/ | |
function vpm_custom_tinymce( $settings ) { | |
// Define our custom formats | |
$style_formats = array( | |
array( | |
// Your style format here | |
), | |
array( | |
// Your 2nd style format here | |
), | |
); | |
// We need the style formats in JSON format | |
$settings['style_formats'] = json_encode( $style_formats ); | |
// Return the $settings variable, | |
// now with our custom formats | |
return $settings; | |
} | |
add_filter( 'tiny_mce_before_init', 'vpm_custom_tinymce' ); |
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 | |
// Replace lines 8–16 in the previous file with the block below: | |
$style_formats = array( | |
array( | |
'title' => 'Pull Quote', | |
'block' => 'aside', | |
'classes' => 'pull-quote', | |
'wrapper' => true, | |
'styles' => array( | |
'float' => 'right', | |
'width' => '40%', | |
'borderLeft' => '4px solid black', | |
'margin' => '0 0 0 20px', | |
'padding' => '0 0 0 15px', | |
'fontStyle' => 'italic' | |
), | |
), | |
); |
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 | |
// Arrays all the way down... | |
$style_formats = array( | |
array( | |
'title' => 'Pull Quote', | |
'block' => 'aside', | |
'classes' => 'pull-quote', | |
'wrapper' => true, | |
'styles' => array( | |
'float' => 'right', | |
'width' => '40%', | |
'borderLeft' => '4px solid black', | |
'margin' => '0 0 0 20px', | |
'padding' => '0 0 0 15px', | |
'fontStyle' => 'italic' | |
), | |
), | |
array( | |
'title' => 'No Indent paragraph', | |
'selector' => 'p', | |
'classes' => 'no-indent', | |
'wrapper' => true, | |
), | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment