Skip to content

Instantly share code, notes, and snippets.

@chrisvanpatten
Last active October 18, 2016 16:03
Show Gist options
  • Save chrisvanpatten/56a7880f730b58f70c93 to your computer and use it in GitHub Desktop.
Save chrisvanpatten/56a7880f730b58f70c93 to your computer and use it in GitHub Desktop.
Register custom style formats to TinyMCE in WordPress
<?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' );
<?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'
),
),
);
<?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