Skip to content

Instantly share code, notes, and snippets.

@kfriend
Last active December 14, 2015 07:09
Show Gist options
  • Save kfriend/5048507 to your computer and use it in GitHub Desktop.
Save kfriend/5048507 to your computer and use it in GitHub Desktop.
Add a WordPress editor "Styles" drop down with top and bottom margin options
<?php
// Enable styles dropdown
add_filter('mce_buttons_2', function ($buttons) {
array_unshift($buttons, 'styleselect');
return $buttons;
});
// Register editor "Styles" drop down classes
add_filter('tiny_mce_before_init', function($styles) {
$classed = array();
$sides = array(
'bottom',
'top',
'ends',
);
foreach ($sides as $side)
{
for ($i = 1; $i <= 4; $i++)
{
$classes[] = array(
'title' => "Margin {$side} x{$i}",
'block' => 'span',
'classes' => "margin-{$side}-x{$i} margin-class-applied",
'wrapper' => true,
);
}
}
$styles['style_formats'] = json_encode($classes);
return $styles;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment