Skip to content

Instantly share code, notes, and snippets.

@jimmy89Li
Last active May 3, 2018 12:38
Show Gist options
  • Save jimmy89Li/7c445586e0013d197ebfd67bfb8fa809 to your computer and use it in GitHub Desktop.
Save jimmy89Li/7c445586e0013d197ebfd67bfb8fa809 to your computer and use it in GitHub Desktop.
WordPress TinyMCE customizing
<?php
// Custom font format button
add_filter( 'mce_buttons', 'my_mce_buttons' );
function my_mce_buttons( $buttons ) {
array_unshift( $buttons, 'styleselect' ); // Add custom format selector
$remove = 'formatselect'; if ( ( $key = array_search( $remove, $buttons ) ) !== false ) unset( $buttons[$key] ); // Remove default format selector
return $buttons;
}
// Custom font styles
add_filter( 'tiny_mce_before_init', 'custom_style_formats' );
function custom_style_formats( $init_array ) {
$style_formats = array(
array(
'title' => '.h1',
'block' => 'span',
'classes' => 'overskrift1',
'wrapper' => true,
),
array(
'title' => '.h2',
'block' => 'span',
'classes' => 'overskrift2',
'wrapper' => true,
),
array(
'title' => '.h3',
'block' => 'span',
'classes' => 'overskrift3',
'wrapper' => true,
),
array(
'title' => '.h4',
'block' => 'span',
'classes' => 'overskrift4',
'wrapper' => true,
),
array(
'title' => '.h5',
'block' => 'span',
'classes' => 'overskrift5',
'wrapper' => true,
),
);
$init_array['style_formats'] = json_encode( $style_formats );
return $init_array;
}
// Custom editor-style in TinyMCE
add_filter( 'mce_css', 'fb_mcekit_editor_style');
function fb_mcekit_editor_style($url) {
$url = get_stylesheet_directory_uri() . '/editor-style.css';
return $url;
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment