Advertisement
miriamdepaula

WordPress: Custom TinyMCE styles dropdown

Apr 17th, 2012
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.44 KB | None | 0 0
  1. <?php
  2. add_editor_style();
  3.  
  4. add_filter( 'mce_buttons_2', 'wpmidia_mce_buttons_2' );
  5.  
  6. function wpmidia_mce_buttons_2( $buttons ) {
  7.     array_unshift( $buttons, 'styleselect' );
  8.     return $buttons;
  9. }
  10.  
  11. add_filter( 'tiny_mce_before_init', 'wpmidia_mce_before_init' );
  12.  
  13. function wpmidia_mce_before_init( $settings ) {
  14.  
  15.     $style_formats = array(
  16.         array(
  17.             'title' => 'Button',
  18.             'selector' => 'a',
  19.             'classes' => 'button'
  20.         ),
  21.         array(
  22.             'title' => 'Callout Box',
  23.             'block' => 'div',
  24.             'classes' => 'callout',
  25.             'wrapper' => true
  26.         ),
  27.         array(
  28.             'title' => 'Bold Red Text',
  29.             'inline' => 'span',
  30.             'styles' => array(
  31.                 'color' => '#f00',
  32.                 'fontWeight' => 'bold'
  33.             )
  34.         )
  35.     );
  36.  
  37.     $settings['style_formats'] = json_encode( $style_formats );
  38.  
  39.     return $settings;
  40.  
  41. }
  42.  
  43. /* Style Format Options
  44.  
  45. title [required]              label for this dropdown item
  46.  
  47. selector|block|inline         selector limits the style to a specific HTML
  48. [required]                    tag, and will apply the style to an existing tag
  49.                               instead of creating one
  50.                              
  51.                               block creates a new block-level element with the
  52.                               style applied, and will replace the existing block
  53.                               element around the cursor
  54.                              
  55.                               inline creates a new inline element with the style
  56.                               applied, and will wrap whatever is selected in the
  57.                               editor, not replacing any tags
  58.  
  59. classes [optional]            space-separated list of classes to apply to the
  60.                               element
  61.  
  62. styles [optional]             array of inline styles to apply to the element
  63.                               (two-word attributes, like font-weight, are written
  64.                               in Javascript-friendly camel case: fontWeight)
  65.  
  66. attributes [optional]         assigns attributes to the element (same syntax as styles)
  67.  
  68. wrapper [optional,            if set to true, creates a new block-level element
  69. default = false]              around any selected block-level elements
  70.  
  71. exact [optional,              disables the “merge similar styles” feature, needed
  72. default = false]              for some CSS inheritance issues
  73.  
  74. */
  75.  
  76. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement