visual editor - How can I change TinyMCE's default block format?

admin2025-06-02  1

I have a particular post type where I want the editor's default format block to be H3. So, when you create a new empty post and begin typing in the editor, the text would automatically default to being an H3.

Currently the default is set to be a Paragraph, which means even if I create some text and set it to be Heading 3 (H3), when I create a new line the block format automatically goes back to Paragraph, too.

As a test, I even removed all the block formats except for H3, but that didn't work—the block format dropdown displays "Heading 3," but the text is still formatted as a paragraph (<p>).

To be clear, I do still want control over the block format. I just want to be able to change the default.

Here's my failed attempt to remove everything except H3:

function set_h3_default($init) {
  $block_formats = array(
    'Heading 3=h3',
  );
  $init['block_formats'] = implode(';', $block_formats);

  return $init;
}
add_filter('tiny_mce_before_init', 'set_h3_default');

转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1748829341a314068.html

最新回复(0)