غیرفعال کردن گوتنبرگ
- ۰۱ دی ۱۴۰۲
- بدون نظر
- فانکشن های وردپرس
- گزارش خطا
فانکشن 1:
اگر توی محیط وردپرس نیازی به ادیتور گوتنبرگ ندارید، از قطعه کد زیر میتونید این صفحه ساز رو غیرفعال کنید.
نحوه استفاده:
بنا به نیازتون، یکی از فانکشن های زیر رو انتهای فایل function.php یا functions.php قالب فعال تون قرار بدید.
نکته:
فانکشن 3 جهت غیرفعال کردن گوتنبرگ داخل یک پست تایپ خاص قابل استفاده است.
بنابراین به جای عبارت your_post_type، باید پست تایپ مد نظرتون رو بنویسید.
(برای مثال product برای غیرفعال کردن گوتنبرگ فقط در صفحه ادیت محصولات)
/** Function 1 **/
if (version_compare($GLOBALS['wp_version'], '5.0-beta', '>')) {
// WP > 5 beta
add_filter('use_block_editor_for_post_type', '__return_false', 100);
} else {
// WP < 5 beta
add_filter('gutenberg_can_edit_post_type', '__return_false');
}
****************************************
/** Function 2 **/
// Disable Gutenberg on the back end.
add_filter( 'use_block_editor_for_post', '__return_false' );
// Disable Gutenberg for widgets.
add_filter( 'use_widgets_block_editor', '__return_false' );
add_action( 'wp_enqueue_scripts', function() {
// Remove CSS on the front end.
wp_dequeue_style( 'wp-block-library' );
// Remove Gutenberg theme.
wp_dequeue_style( 'wp-block-library-theme' );
// Remove inline global CSS on the front end.
wp_dequeue_style( 'global-styles' );
// Remove classic-themes CSS for backwards compatibility for button blocks.
wp_dequeue_style( 'classic-theme-styles' );
}, 20 );
****************************************
/** Function 3 **/
// If you want to disable Gutenberg for a specific post type, use the code below:
add_filter( 'use_block_editor_for_post_type', function( $enabled, $post_type ) {
return 'your_post_type' === $post_type ? false : $enabled;
}, 10, 2 );
اشتراک گذاری فانکشن: