禁止屏蔽古腾堡(Gutenberg)编辑器的实用代码收集

WORDPRESS SEO

wordpress自5.0后的版本,默认编辑器叫古腾堡(Gutenberg),甲爸不是说古腾堡不好,它自有其优势和价值(好似诸多微信公众号编辑器那样,可以让内容有丰富的版式,文章也更有更高阅读和流量——因为国外SEO环境不一样,相对公平一些,不像咱中国的搜索厂商那么封闭和内卷~注重内页排版是有回报的)。仅从SEO角度来看,这个编辑器的使用较影响发文速度。还是想法换回经典编辑器,更适合。

要换很简单。甲爸所有的wordpress网站都安装了wpjam_basic插件。勾选不使用即可。

但还有其他方式,用自定义代码的方式。或许,这种更为彻底——屏蔽古腾堡编辑器的同时,在前端屏蔽所有相关的样式

//disable Gutenberg editor , source https://blog.brain1981.com
add_filter( 'use_block_editor_for_post', '__return_false' );
add_filter( 'use_widgets_block_editor', '__return_false' );

//remove classic-theme-styles CSS
function brain1981_remove_wp_unused_css(){
wp_dequeue_style( 'wp-block-library' );
wp_dequeue_style( 'wp-block-library-theme' );
wp_dequeue_style( 'wc-blocks-vendors-style' );
wp_dequeue_style( 'wc-blocks-style' );
wp_dequeue_style( 'bp-member-block' );
wp_dequeue_style( 'bp-members-block' );
wp_dequeue_style( 'classic-theme-styles' );
}
add_action( 'wp_enqueue_scripts', 'brain1981_remove_wp_unused_css', 100 );

来源参见:https://blog.brain1981.com/2989.html

虽然甲爸无需再去实践验证,但凭常识就能判断,此代码是有效可用的。

此外,还有两种屏蔽禁止古腾堡编辑器的代码可供参考:

// 禁用古腾堡方法一
// 1.禁用WP5.0+古滕堡反人类编辑器,使用Gutenberg模块经典文章编辑器;
add_filter('use_block_editor_for_post', '__return_false');
// 2.禁止WordPress新版本文章编辑器前端加载样式文件
remove_action('wp_enqueue_scripts', 'wp_common_block_scripts_and_styles');

// 禁用古腾堡方法二
if( wb_opt('gutenberg_switch') ) {
add_filter('use_block_editor_for_post_type',function($is_user,$post_type){return false;},10,2);
//WordPress 5.0+移除 block-library CSS
add_action( 'wp_enqueue_scripts', 'tonjay_remove_block_library_css', 100 );
function tonjay_remove_block_library_css() {
wp_dequeue_style( 'wp-block-library' );
}
}

选择用吧!如果这还不能彻底禁止古腾堡。那真是太难了!

相关文章

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注