最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

tinymce - Limit Block format tags in WordPress wp_editor

programmeradmin0浏览0评论

I'm working on a custom meta box and i am trying to limit the Block format tag to just P, H3 and H4 tags, i did it this way and not sure why it doesn't display the block format dropdown;

wp_editor( $content, 'fm_display_callback', array (
    'media_buttons' => false,
    'textarea_rows' => 5,
    'quicktags' => array( 
        'buttons' => 'strong,em,del,ul,ol,li,close' 
    ),
    'tinymce'       => array(
        'toolbar1'      => 'bold,italic,underline,bullist,numlist,alignleft,forecolor,aligncenter,alignright,link,unlink,undo,redo',
        'toolbar2'      => '',
        'toolbar3'      => '',
        'block_formats' => "Paragraph=p; Heading 3=h3; Heading 4=h4",
    ),
) );

as listed on WordPress Codex, it doesnt work for some reason. I have as well tried making the block_formats key into an array like this;

 'block_formats' => array(
      'Paragraph=p',
      'Heading 3=h3',
      'Heading 4=h4',
 )

and like this;

 'block_formats' => array(
      'Paragraph' => 'p',
      'Heading 3' => 'h3',
      'Heading 4' => 'h4',
 )

Not sure what i'm missing that is preventing the block format to display, as this is what i get visually (No dropdown)

I'm working on a custom meta box and i am trying to limit the Block format tag to just P, H3 and H4 tags, i did it this way and not sure why it doesn't display the block format dropdown;

wp_editor( $content, 'fm_display_callback', array (
    'media_buttons' => false,
    'textarea_rows' => 5,
    'quicktags' => array( 
        'buttons' => 'strong,em,del,ul,ol,li,close' 
    ),
    'tinymce'       => array(
        'toolbar1'      => 'bold,italic,underline,bullist,numlist,alignleft,forecolor,aligncenter,alignright,link,unlink,undo,redo',
        'toolbar2'      => '',
        'toolbar3'      => '',
        'block_formats' => "Paragraph=p; Heading 3=h3; Heading 4=h4",
    ),
) );

as listed on WordPress Codex, it doesnt work for some reason. I have as well tried making the block_formats key into an array like this;

 'block_formats' => array(
      'Paragraph=p',
      'Heading 3=h3',
      'Heading 4=h4',
 )

and like this;

 'block_formats' => array(
      'Paragraph' => 'p',
      'Heading 3' => 'h3',
      'Heading 4' => 'h4',
 )

Not sure what i'm missing that is preventing the block format to display, as this is what i get visually (No dropdown)

Share Improve this question asked Sep 10, 2019 at 19:02 Kolawole Emmanuel IzzyKolawole Emmanuel Izzy 2031 silver badge8 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 2

You need to add formatselect in one of the toolbars, and WordPress by default have it in toolbar1:

wp_editor( $content, 'fm_display_callback', array(
    ...
    'tinymce' => array(
        'toolbar1' => 'formatselect,bold,italic,...',
        ...
    ),
) );

Check this and https://www.tiny.cloud/docs-4x/configure/content-formatting/#block_formats.

发布评论

评论列表(0)

  1. 暂无评论