구텐베르크 CSS 삭제
WordPress v4.9.8에 Gutenberg 플러그인이 설치되어 있으며, 동봉되어 있는 CSS를 제거하려고 합니다.
다음 시트가 포함되어 있습니다.
<link rel='stylesheet' id='wp-block-library-css' href='/wp-content/plugins/gutenberg/build/block-library/style.css?ver=1535795173' type='text/css' media='all' />
다음을 시도했습니다.
add_action( 'wp_print_styles', 'wps_deregister_styles', 100 );
function wps_deregister_styles() {
wp_dequeue_style( 'wp-block-library-css' );
wp_deregister_style( 'wp-block-library-css' );
}
그리고 이것들의 변형도 있지만, 그 파일은 지속됩니다.어떻게 하면 제거할 수 있나요?
제 의견보다 더 완벽한 답변으로 덧붙입니다.
를 삭제해야 합니다.-css
큐를 해제하려고 할 때 사용합니다.이것은 HTML 마크업에 추가되며 css 파일의 실제 태그는 추가되지 않습니다.
코드를 검색하면(Gutenberg가 코어로 롤링됨에 따라 엔큐의 위치가 변경될 수 있음) 다음을 찾을 수 있습니다.
wp_enqueue_style( 'wp-block-library' );
보다시피 없다-css
이 솔루션은 스타일 디큐잉에 문제가 있는 다른 플러그인에 사용할 수 있습니다.
편집: 이것은 아직 약간의 설득력을 가지고 있기 때문에, 이것을 처리하기 위한 코드는 다음과 같습니다.
add_action( 'wp_print_styles', 'wps_deregister_styles', 100 );
function wps_deregister_styles() {
wp_dequeue_style( 'wp-block-library' );
}
이 코드를 사용하여 기본 스타일을 제거합니다.
//Disable gutenberg style in Front
function wps_deregister_styles() {
wp_dequeue_style( 'wp-block-library' );
}
add_action( 'wp_print_styles', 'wps_deregister_styles', 100 );
워드프레스 5.1을 사용합니다.가장 높은 투표율을 얻은 답변을 시도했지만, 제게는 효과가 없었습니다.'wp_enqueue_scripts'
대신'wp_print_styles'
효과가 있습니다.
다음은 Blat 스타일시트를 로드하지 않고 Gutenberg를 제거할 수 있는 WordPress 5.1 솔루션 전체입니다.
// Disable Gutenberg editor.
add_filter('use_block_editor_for_post_type', '__return_false', 10);
// Don't load Gutenberg-related stylesheets.
add_action( 'wp_enqueue_scripts', 'remove_block_css', 100 );
function remove_block_css() {
wp_dequeue_style( 'wp-block-library' ); // Wordpress core
wp_dequeue_style( 'wp-block-library-theme' ); // Wordpress core
wp_dequeue_style( 'wc-block-style' ); // WooCommerce
wp_dequeue_style( 'storefront-gutenberg-blocks' ); // Storefront theme
}
편집:
WordPress 5.2에서도 동작하며, WooCommerce와 Storefront 테마에 의해 추가된 스타일시트를 처리하기 때문에 새로운 플러그인에서 다음 설정 중 하나를 설정했습니다.
https://wordpress.org/plugins/extra-settings-for-woocommerce/
다음 코드를 함수에 붙여 넣습니다.php 파일
function custom_theme_assets() {
wp_dequeue_style( 'wp-block-library' );
}
add_action( 'wp_enqueue_scripts', 'custom_theme_assets', 100 );
이게 도움이 됐으면 좋겠어요.
wp_dequeue_style-approach가 wp-editor-font(wp-editor-font-css)를 디세블로 하지 않았기 때문에 다음 코드를 사용했습니다.
function my_remove_gutenberg_styles($translation, $text, $context, $domain)
{
if($context != 'Google Font Name and Variants' || $text != 'Noto Serif:400,400i,700,700i') {
return $translation;
}
return 'off';
}
add_filter( 'gettext_with_context', 'my_remove_gutenberg_styles',10, 4);
https://github.com/dimadin/disable-google-fonts/blob/master/disable-google-fonts.php 도 참조해 주세요.
2021년에 저는 위의 접근방식 대부분을 시도해 보았지만 모두 실패했습니다.WordPress 코드를 보면 구텐베르크 스타일이 큐잉되지 않았기 때문이라고 생각합니다.제가 찾은 유일한 제거 방법은 인쇄 직전에 제거하는 것입니다.
// This is what works for me.
add_action( 'wp_print_styles', 'wps_deregister_styles', 9999 );
function wps_deregister_styles() {
global $wp_styles;
$wp_styles->remove('wp-block-library');
}
이것은 질문에 대한 해답은 아니지만, 나와 같은 다른 사람들은 이 질문이 시사하는 바는 있지만 해결하지 못하는 것을 해결하려고 노력하게 된 것 같습니다.how do you remove the inline (WP 5.5+) storefront-gutenberg-blocks-inline-css so you can use the editor even though it's using white on white or black on black in the storefront theme?
이하가 바로 그것입니다.당신의 기능에 넣으세요.php 파일 또는 플러그인.
function clean_storefront_gutenberg_block_editor_customizer_css( $string ) {
// return empty so the editor doesn't suck
return '';
}
add_filter( 'storefront_gutenberg_block_editor_customizer_css', 'clean_storefront_gutenberg_block_editor_customizer_css' );
이렇게 하면 생성된 CSS가 비활성화되기 때문에 백엔드 에디터에 아무것도 추가되지 않습니다.프런트 엔드는 변경되지 않습니다.
프런트 엔드에 구텐베르크 블록 라이브러리 CSS를 로드하지 않도록 합니다.
function smartwp_remove_wp_block_library_css()
{
wp_dequeue_style('wp-block-library');
wp_dequeue_style('wp-block-library-theme');
wp_dequeue_style('wc-block-style'); // Remove WooCommerce block CSS
}
add_action('wp_enqueue_scripts', 'smartwp_remove_wp_block_library_css', 999);
위의 답변 중 어느 것도 블록 편집기에서 모든 스타일을 제거하지 못했습니다. 다음 답변은 나에게 효과가 있었습니다.
add_action( 'admin_print_styles', function() {
global $wp_styles;
$stylesToRemove = ["wp-reset-editor-styles", "wp-format-library", "wp-block-library", "wp-block-library-theme", "wp-block-directory", "wp-edit-blocks"];
foreach ($stylesToRemove as $styleToRemove) {
foreach ($wp_styles->registered as $style) {
$dep = array_search($styleToRemove, $style->deps);
if ($dep !== false) {
unset($style->deps[$dep]);
}
}
wp_deregister_style($styleToRemove);
}
}, 1 );
add_action('wp_enqueue_scripts', 'wps_deregister_styles', 200);
저는 좋아요.
최근 구텐베르크의 최신 업데이트가 나왔기 때문에 WordPress에서 wp-block-library를 어떻게 삭제해야 하는지 많은 사람들이 궁금해하고 있습니다.가이드에서 보듯이 add_action에서 100을 참조해야 합니다.
는 Firslty를 합니다.wp_dequeue_style
★★★★★★에wp-block-library
그리고 이렇게 부르죠.
add_action( 'wp_enqueue_scripts', 'custom_function', 100 );
언급URL : https://stackoverflow.com/questions/52277629/remove-gutenberg-css
'itsource' 카테고리의 다른 글
JavaScript에서 스크립트 태그로 JSON을 읽는 방법은 무엇입니까? (0) | 2023.02.10 |
---|---|
간단한 jQuery 스크립트를 WordPress에 추가하려면 어떻게 해야 합니까? (0) | 2023.02.10 |
ASP.NET Core - 'JsonRequestBehavior' 이름이 현재 컨텍스트에 없습니다. (0) | 2023.02.10 |
Swift에서 사전을 JSON으로 변환 (0) | 2023.02.10 |
앵커 태그의 디폴트를 방지하는 방법 (0) | 2023.02.10 |