Last active
December 14, 2015 07:09
-
-
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
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 | |
// 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