51工具盒子

依楼听风雨
笑看云卷云舒,淡观潮起潮落

WordPress 区块编辑器中只显示自己需要的区块

WordPress古腾堡大家已经很熟悉了,本站长也经常使用WordPress的古腾堡或WordPress的经典编辑器,对于一些两者之间来回换着用的用户可能已经很烦了,所以在还会有一部分人选择在古腾堡里选择 经典编辑器 ,这样方便了很多,但夏柔发现随着WordPress的版本更新,新版本发布地址《WordPress5.4版本》古腾堡的区块也随着增加,这样不仅对国内用户使用的过程当中十分的麻烦,甚至有80%的区块我们都用不上,夏柔参考了PHP中文网的代码,写了这篇,给大家参考一下(很有价值)

以下代码添加至主题的function.php中:

add_filter( 'allowed_block_types', 'zm_allowed_block_types', 10, 2 );
function zm_allowed_block_types( $allowed_blocks, $post ) {
$allowed_blocks = array(
'core/image',
'core/paragraph',
'core/heading',
'core/list',
);
// 在页面编辑中单独显示的区块
if( $post->post_type === 'page' ) {
$allowed_blocks[] = 'core/shortcode';
}
return $allowed_blocks;
}

把想显示的区块名称添加进去即可。

更多的区块名称:

core/shortcode
core/image
core/gallery
core/heading
core/quote
core/embed
core/list
core/separator
core/more
core/button
core/pullquote
core/table
core/preformatted
core/code
core/html
core/freeform
core/latest-posts
core/categories
core/cover (previouslycore/cover-image)
core/text-columns
core/verse
core/video
core/audio
core/block
core/paragraph
core-embed/twitter
core-embed/youtube
core-embed/facebook
core-embed/instagram
core-embed/wordpress
core-embed/soundcloud
core-embed/spotify
core-embed/flickr
core-embed/vimeo
core-embed/animoto
core-embed/cloudup
core-embed/collegehumor
core-embed/dailymotion
core-embed/funnyordie
core-embed/hulu
core-embed/imgur
core-embed/issuu
core-embed/kickstarter
core-embed/meetup-com
core-embed/mixcloud
core-embed/photobucket
core-embed/polldaddy
core-embed/reddit
core-embed/reverbnation
core-embed/screencast
core-embed/scribd
core-embed/slideshare
core-embed/smugmug
core-embed/speaker
core-embed/ted
core-embed/tumblr
core-embed/videopress
core-embed/wordpress-tv
赞(0)
未经允许不得转载:工具盒子 » WordPress 区块编辑器中只显示自己需要的区块