Remove Gutenberg CSS - css

I have Gutenberg plugin installed in WordPress v4.9.8 and am trying to remove the CSS that comes with it so I can supply my own.
This is the sheet that gets included:
<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' />
I have tried the following:
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' );
}
As well as variations of this, but the file persists. How can I remove it?

I'm adding this as a more complete answer than my comment:
You need to remove the -css when trying to dequeue the script. That's added to the HTML markup and not the actual tag for the css file.
If you search the code (the location of the enqueue may change as Gutenberg gets rolled into core), you can find:
wp_enqueue_style( 'wp-block-library' );
As you can see, there is no -css. This solution may work for other plugins that people have trouble dequeuing styles.
Edit:
Since this still gets some traction, here is the code to handle it:
add_action( 'wp_print_styles', 'wps_deregister_styles', 100 );
function wps_deregister_styles() {
wp_dequeue_style( 'wp-block-library' );
}

I am use this code to to remove default style.
//Disable gutenberg style in Front
function wps_deregister_styles() {
wp_dequeue_style( 'wp-block-library' );
}
add_action( 'wp_print_styles', 'wps_deregister_styles', 100 );

I use Wordpress 5.1. Tried the most upvoted answers and they didn't work for me, 'wp_enqueue_scripts' instead of 'wp_print_styles' does the trick.
Here is my whole WordPress 5.1 solution to get rid of Gutenberg without bloat stylesheets loading:
// 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
}
Edit:
It works with WordPress 5.2 as well and because it handles the stylesheets added by WooCommerce and Storefront theme, I made this one of the settings in my new plugin:
https://wordpress.org/plugins/extra-settings-for-woocommerce/

Paste the following code on your functions.php file
function custom_theme_assets() {
wp_dequeue_style( 'wp-block-library' );
}
add_action( 'wp_enqueue_scripts', 'custom_theme_assets', 100 );
Please like if this has helped you.

As the wp_dequeue_style-approach did not work to disable wp-editor-font (wp-editor-font-css) I used the following code:
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);
Also see https://github.com/dimadin/disable-google-fonts/blob/master/disable-google-fonts.php

In 2021 I tried variations of most of the approaches above and they all failed. Looking at the WordPress code, I believe the reason why is that Gutenberg styles are not enqueued anymore. The only way I have found to remove it is to remove it just before it is printed.
// 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');
}

This doesn't really answer the question, but I suspect others like me have ended up here trying to resolve something this question alludes to but doesn't address: 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?
The following will do just that. Put it in your functions.php file or a plugin.
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' );
This just defuses the generated CSS so there's nothing appended to the back-end editor. The front-end remains unchanged.

Remove Gutenberg Block Library CSS from loading on the frontend
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);

None of the above answers removed all the styles in the block editor, the following worked for me:
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);
Works for me.

As the latest Gutenberg update has been released recently, a lot of people are wondering how to remove wp-block-library from WordPress. As the guide shows, below you need you to reference the 100 in your add_action.
Firslty, you must create a function that holds your wp_dequeue_style for wp-block-library and then call it as such:
add_action( 'wp_enqueue_scripts', 'custom_function', 100 );

Related

I have a question regarding wp_dequeue_script

I would like to block to load comment-reply.js file on pages.
Theme functions.php,
function theme_enqueue_scripts() {
if (is_singular() && get_option('thread_comments'))
wp_enqueue_script('comment-reply'); }
So, I added codes to block that js file in child theme's functions.php,
function comment_load_script() {
if ( is_single()) {return;}
wp_dequeue_script('comment-reply');}
add_action( 'wp_enqueue_scripts', 'comment_load_script' );
However, comment-reply.js is still loaded on every page. I need your help. Thanks in advance. :)
Try this code. Its working fine.
function comment_load_script(){
wp_deregister_script( 'comment-reply' );
}
add_action('init','comment_load_script');

WooCommerce - How to remove sidebar

I need to remove sidebar into my woocommerce store.
I have tried with backend in option theme and in each category but resultless.
I tried also:
1.file wp-template-hooks.php
removed--> do_action(..
2.file archive-product.php
removed--> do_action(..
insert in file function.php in theme dir and function.php in woocommerce dir
remove_action( 'woocommerce_sidebar', 'woocommerce_get_sidebar', 10 );
into database there is 2 tables with 2 fields serialised but is a risk change this.
resulless.
I finished the ideas.
Where is saved into db the visibility of sidebar? or the variable?
Can you help me?
Thanks
Ale
I just wanted to update this post for WooCommerce version 3.2.3 - 2017
OK the WooCommerce Plugin includes a folder with all the template files if you want to make changes to the template on a custom theme or child theme you need to copy all of the desired template into a folder called woocommerce in your root theme folder. This will overwrite the plugin templates and will allow for WooCommerce updates with overwriting your custom changes. These templates have all of the do_actions and hooks in the comments so it makes it easy to understand how it's working.
That said WooCommerce has hooks that allow for you to add or remove blocks of code you can check out the API Docs here.
To remove the side bar you need to add this into your functions.php file in your theme setup function
remove_action( 'woocommerce_sidebar', 'woocommerce_get_sidebar', 10 );
Please, add this code to your functions.php
function mb_remove_sidebar() {
return false;
}
add_filter( 'is_active_sidebar', 'mb_remove_sidebar', 10, 2 );
Add to functions.php the following line:
add_action( 'init', function () {
remove_action( 'woocommerce_sidebar', 'woocommerce_get_sidebar', 10 );
} );
You have already integrated WooCommerce in your theme?
If not, try to do this three steps for integration WooCommerce in your theme.
After that, remove get_sidebar(); from your_theme/woocommerce.php
It works fine for me. Screenshot here.
Hope it helps.
Further to #maksim-borodov's answer, I wanted to hide the sidebar conditionally, i.e. only on Product pages. Here's how:
function remove_wc_sidebar_conditional( $array ) {
// Hide sidebar on product pages by returning false
if ( is_product() )
return false;
// Otherwise, return the original array parameter to keep the sidebar
return $array;
}
add_filter( 'is_active_sidebar', 'remove_wc_sidebar_conditional', 10, 2 );
Add to functions.php the following line:
remove_action( 'woocommerce_sidebar', 'woocommerce_get_sidebar', 10);
I am using GeneratePress (free version), so the other solutions didn't work for me.
This page gave me the answer: https://docs.generatepress.com/article/sidebar-layout/#sidebar-filter
add_filter( 'generate_sidebar_layout', function( $layout ) {
// If we are on a woocommerce page, set the sidebar
if ( function_exists( 'is_woocommerce' ) && is_woocommerce() ) {
return 'no-sidebar';
}
// Or else, set the regular layout
return $layout;
} );
This can be done by woocommerce sidebar plugin. If you want to remove by code add this code to functions.php,
if (!class_exists( 'WooCommerce' ) ) {return;}
if(is_cart() || is_checkout() || is_product() || is_shop() || is_account_page()){
?>
<style type="text/css">
#secondary {
display: none;
}
#primary {
width:100%;
}
</style>
<?php
}
}
Here is how to remove the sidebar :-
go to wp-content/plugins/woocommerce
in file single-product.php remove the following code -
<?php
/**
* woocommerce_sidebar hook
*
* #hooked woocommerce_get_sidebar - 10
*/
do_action('woocommerce_sidebar');
?>
next edit the file archive-product.php and remove the following code -
<?php
/**
* woocommerce_sidebar hook
*
* #hooked woocommerce_get_sidebar - 10
*/
do_action('woocommerce_sidebar');
?>
(tip* before deleting this, copy and paste the entire code from this page into a seperate text file on your HD...that way you can always paste the original code back into this folder if anything goes wrong)

Remove YouTube embedding with wp_oembed_remove_provider()

I am trying to remove YouTube embedding from some of my WordPress output, so it only shows the link.
I have tried the following code without any luck.
wp_oembed_remove_provider('#http://(www\.)?youtube\.com/watch.*#i');
wp_oembed_remove_provider('#https://(www\.)?youtube\.com/watch.*#i');
wp_oembed_remove_provider('#http://youtu\.be/.*#i');
wp_oembed_remove_provider('#https://youtu\.be/.*#i');
echo apply_filters("the_content", $result->text);
What am I doing wrong? And how am I doing this correctly?
Chances are you're at a point where it's too late to remove the providers. Try hooking into plugins_loaded or init:
add_action( 'init', 'so26743803_wp_oembed_remove_provider' );
function so26743803_wp_oembed_remove_provider(){
wp_oembed_remove_provider('#https://youtu\.be/.*#i');
// etc.
}
Edit (untested): unsetting providers with the oembed_providers filter (see this Q):
add_filter( 'oembed_providers', 'so26743803_oembed_providers' );
function so26743803_oembed_providers( $providers )
{
unset( $providers['#http://youtu\.be/.*#i'] );
// etc.
return $providers;
}

WP Elegant Themes > hide tinymce buttons?

I have an elegant theme installed in my Wordpress website, and I am wondering how i can hide or remove the shortcode buttons in the tinymce (thing) that are generated by the Elegant Theme (admin area WP). I have been trying to look up the action hook and remove it and also play with the CSS of the buttons, but nothing helped. any idea's on how to remove these small buttons from the backend of my WP website?
This is the related code I've found:
add_filter('mce_buttons', 'et_filter_mce_button');
add_filter('mce_external_plugins', 'et_filter_mce_plugin');
function et_filter_mce_button($buttons) {
array_push( $buttons, '|', 'et_learn_more', 'et_box', 'et_button', 'et_tabs', 'et_author' );
return $buttons;
}
Create a plugin and remove the filters:
<?php
/**
* Plugin Name: Remove ET MCE Buttons
*/
add_action( 'admin_init', 'remove_et_so_19084867' );
function remove_et_so_19084867() {
remove_filter( 'mce_buttons', 'et_filter_mce_button' );
remove_filter( 'mce_external_plugins', 'et_filter_mce_plugin' );
}
A user from the Elegant Themes forum referenced this post: https://wordpress.stackexchange.com/questions/103347/removing-buttons-from-the-editor and said:
Place the following code in your child theme functions.php:
// HIDE TINYMCE CUSTOM BUTTONS
function tinymce_editor_buttons($buttons) {
return array();
}
function tinymce_editor_buttons_second_row($buttons) {
return array();
}
add_filter("mce_buttons", "tinymce_editor_buttons", 99);
add_filter("mce_buttons_2", "tinymce_editor_buttons_second_row", 99);
This removes all buttons inserted by Divi and other plugins. If you need to keep any buttons you can include the corresponding ID inside of return array();. Also, if you're using the plugin TinyMCE Advanced, the standard buttons stay in place anyway.

what to do after registering and enqueing a css file inside a plugin folder to use it

I have been looking for an answer for this in SOF but didn't find a clear answer
I have a plugin that forces pages to be shown when certain conditions are met. but when i try to include css files for styling i get no response .
I tried to include the file using normal html and this was a failure
then tried the wp_register_style and wp_enqueue_style as such:
function rw_add_style(){
$rw_path = plugins_url('kawaleb/style.css');
wp_register_style('testili',plugins_url('kawaleb/style.css'));
wp_enqueue_style( 'testili' );
}
add_action ('wp_enqueue_scripts','rw_add_style');
wp_enqueue_style( 'testili' );
}
I placed this code on the page that should be shown when the conditions are met
What I don't know here is how to procede after enqueing !
do I need to use html to include the stylesheet file ( and then what is the use of enqueing ?) or does it do that by itself (and then what I am missing here ? )
In the doc of codex they dont go further than telling you to register the style then enqueue it !!!
Thank you all :)
You don't need to register the style, you can just enqueue it. Also, you mentioned that you've put the code in the file where you'd like it to display, you should put it in the index file of your plugin, so in /your-plugin/index.php or whatever the main file is called, add this code:
function rw_add_style() {
wp_enqueue_style( 'testili', plugins_url( 'kawaleb/style.css' ) );
}
add_action( 'wp_enqueue_scripts', 'rw_add_style' );
If you need it only on a certain page then you should add your conditional within the function, so you could do this for example:
function rw_add_style() {
global $post;
if ( $post->post_name == 'post_name' ) {
wp_enqueue_style( 'testili', plugins_url( 'kawaleb/style.css' ) );
}
}
add_action( 'wp_enqueue_scripts', 'rw_add_style' );
And you can work out what the post name is for the page you need to enqueue it for by temporarily adding the following code to the page template:
global $post;
echo $post->post_name;
To be clear, you don't need to add any html <link> to include the CSS as you're right, there would be no point in enqueuing it then. Just add the enqueue as I described above in the main index file of your plugin and it will be automatically included in the wp_head() in your header and output just before the </head>.
I hope this helps. Good luck. =)

Resources