Skip to content

Instantly share code, notes, and snippets.

@bryanwillis
Last active April 18, 2018 05:17
Show Gist options
  • Save bryanwillis/0f24d307631f15e8bd67 to your computer and use it in GitHub Desktop.
Save bryanwillis/0f24d307631f15e8bd67 to your computer and use it in GitHub Desktop.
Tinymce Advanced Style Formats Example for Wordpress. Example of using HTML5 formatting in TINYMCE Visual Editor for Wordpress taken from this example on TinyMCE's site ( link https://www.tinymce.com/docs/demo/format-html5/ ).
<?php
/**
* HTML5 Styles Dropdown
*
* @author Bryan Willis
* @link https://www.tinymce.com/docs/demo/format-html5/
*/
function mce_html5_formatting( $init ) {
//$init['block_formats'] = 'Paragraph=p;Heading 1=h1;Heading 2=h2;Heading 3=h3;Heading 4=h4;Heading 5=h5;Heading 6=h6;';
$style_formats =array(
array(
'title' => 'Headers',
'items' => array(
array(
'title' => 'Header 1',
'block' => 'h1'
) ,
array(
'title' => 'Header 2',
'block' => 'h2'
) ,
array(
'title' => 'Header 3',
'block' => 'h3'
) ,
array(
'title' => 'Header 4',
'block' => 'h4'
) ,
array(
'title' => 'Header 5',
'block' => 'h5'
) ,
array(
'title' => 'Header 6',
'block' => 'h6'
)
)
) ,
array(
'title' => 'Blocks',
'items' => array(
array(
'title' => 'Paragraph <p>',
'block' => 'p'
) ,
array(
'title' => 'Arbitrary Division <div>',
'block' => 'div'
) ,
array(
'title' => 'Preformatted Text <pre>',
'block' => 'pre'
)
)
) ,
array(
'title' => 'Containers',
'items' => array(
array(
'title' => 'Section',
'block' => 'section',
'wrapper' => 'true',
'merge_siblings' => 'false'
) ,
array(
'title' => 'Blockquote',
'block' => 'blockquote',
'wrapper' => 'true',
'icon' => 'blockquote'
) ,
array(
'title' => 'Figure',
'block' => 'figure',
'wrapper' => 'true'
)
)
)
);
$init['style_formats'] = json_encode( $style_formats );
$init['style_formats_merge'] = false;
return $init;
}
add_filter('tiny_mce_before_init', 'mce_html5_formatting');
//* Move the Style Select Button First
function mce_add_buttons_styleselect( $buttons ){
array_splice( $buttons, 1, 0, 'styleselect' );
return $buttons;
}
add_filter( 'mce_buttons_2', 'mce_add_buttons_styleselect' );
// */
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment