Skip to content

Instantly share code, notes, and snippets.

@roborourke
Created May 23, 2012 13:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save roborourke/2775231 to your computer and use it in GitHub Desktop.
Save roborourke/2775231 to your computer and use it in GitHub Desktop.
Code by @alisothegeek to enable a styles dropdown in the WP tinymce editor
<?php
/*
* Custom styles for tiny mce
* HT: http://alisothegeek.com/2011/05/tinymce-styles-dropdown-wordpress-visual-editor/
*/
add_filter( 'mce_buttons_2', 'my_mce_buttons_2' );
function my_mce_buttons_2( $buttons ) {
array_unshift( $buttons, 'styleselect' );
return $buttons;
}
add_filter( 'tiny_mce_before_init', 'my_mce_before_init' );
function my_mce_before_init( $settings ) {
$style_formats = array(
array(
'title' => 'Button',
'selector' => 'a',
'classes' => 'button'
),
array(
'title' => 'Intro paragraph',
'selector' => 'p',
'classes' => 'intro'
),
array(
'title' => 'Callout',
'selector' => 'p',
'classes' => 'callout'
)
);
$settings[ 'style_formats' ] = json_encode( $style_formats );
return $settings;
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment