WordPress is injecting class="wp-block-heading"
to all the heading tags, like h1, h2, and h3. Even though I don't need it in my style sheet. I tried removing it with the following codes, but it didn't work.
// Remove wp-block-library-css add_action( 'wp_print_styles', 'wps_deregister_styles', 100 ); function wps_deregister_styles() { wp_dequeue_style( 'wp-block-library' ); }
And this as well:
// Remove gutenberg block library css from loading on frontend function 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 wp_dequeue_style( 'global-styles' ); // REMOVE theme.json } // add_action( 'wp_enqueue_scripts', 'remove_wp_block_library_css', 100 );
quote One of the affected URLs: /
WordPress is injecting class="wp-block-heading"
to all the heading tags, like h1, h2, and h3. Even though I don't need it in my style sheet. I tried removing it with the following codes, but it didn't work.
// Remove wp-block-library-css add_action( 'wp_print_styles', 'wps_deregister_styles', 100 ); function wps_deregister_styles() { wp_dequeue_style( 'wp-block-library' ); }
And this as well:
// Remove gutenberg block library css from loading on frontend function 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 wp_dequeue_style( 'global-styles' ); // REMOVE theme.json } // add_action( 'wp_enqueue_scripts', 'remove_wp_block_library_css', 100 );
quote One of the affected URLs: https://www.theidioms.com/face-to-face/
You can use this code instead:
function gauravt_remove_wp_block_heading_class_from_headings($content) {
// Use regular expression to find and remove the class="wp-block-heading" from h1 to h6 tags
$pattern = '/<(h[1-6])\s+class="wp-block-heading"(.*?)>/i';
$replacement = '<$1$2>';
$content = preg_replace($pattern, $replacement, $content);
return $content;
}
// Add the filter to 'the_content' hook
add_filter('the_content', 'gauravt_remove_wp_block_heading_class_from_headings');
See: https://gauravtiwari.org/snippet/remove-classwp-block-heading-from-heading/
you can remove the class="wp-block-heading" attribute from your heading tags by modifying your theme's functions.php file or by using a plugin.
Option: Modify functions.php
Go to Appearance > Theme Editor in your WordPress dashboard. Click on the functions.php file on the right-hand side. Add the following code at the end of the file:
function remove_block_css(){
wp_dequeue_style( 'wp-block-library' );
}
add_action( 'wp_enqueue_scripts', 'remove_block_css', 100 );
Click on the "Update File" button to save your changes. Option 2: Use a plugin
Install and activate the "Disable Gutenberg Blocks" plugin from the WordPress plugin repository. Go to Settings > Disable Gutenberg Blocks in your WordPress dashboard. Select the "Disable all Gutenberg blocks" option and save your changes. Both of these options will remove the class="wp-block-heading" attribute from your heading tags in WordPress. However, keep in mind that removing this class may affect the styling of your headings, so you may want to add alternative styles to ensure that your headings still look the way you want them to.