Custom Block Types In RTE?

[ad_1]

Hi, I fond [this]) snippet explaining how to add custom block types to the RTE:
“`
function wholesomecode_tinymce_formatting( $settings ) {
$style_formats = array(
array(
‘title’ => ‘Lead Paragraph’,
‘block’ => ‘p’,
‘classes’ => ‘lead’,
‘wrapper’ => false,
),
);
$settings[‘style_formats’] = json_encode( $style_formats );
return $settings;
}
add_filter( ‘tiny_mce_before_init’, ‘wholesomecode_tinymce_formatting’ );
“`
It seems that the styles dropdown is hidden by default, so the following is necessary as well (as documented [here]) and [here]):
“`
function myplugin_tinymce_buttons( $buttons ) {
//Add style selector to the beginning of the toolbar
array_unshift( $buttons, ‘styleselect’ );

return $buttons;
}
add_filter( ‘mce_buttons_2’, ‘myplugin_tinymce_buttons’ );
“`
Now I’m curious, can we also add custom the custom types in the same dropdown where the other types Paragraph, Heading [1-6] and Preformatted are located? That would be much better UX for the users!

[ad_2]

 

This site will teach you how to build a WordPress website for beginners. We will cover everything from installing WordPress to adding pages, posts, and images to your site. You will learn how to customize your site with themes and plugins, as well as how to market your site online.

Buy WordPress Transfer