You are trying to remove CSS stylesheets generated by a booking plugin on the frontend form and calendar. However, the solution using wp_dequeue_style
and wp_deregister_style
doesn’t seem to work. Here’s a more effective method that directly removes the <link>
tag output for the stylesheets in the frontend.
function remove_booking_plugin_styles()
{
wp_dequeue_style('wpdevelop-bts');
wp_deregister_style('wpdevelop-bts');wp_dequeue_style('wpdevelop-bts-theme');
wp_deregister_style('wpdevelop-bts-theme');
wp_dequeue_style('wpbc-tippy-popover');
wp_deregister_style('wpbc-tippy-popover');
wp_dequeue_style('wpbc-tippy-times');
wp_deregister_style('wpbc-tippy-times');
wp_dequeue_style('wpbc-material-design-icons');
wp_deregister_style('wpbc-material-design-icons');
wp_dequeue_style('wpbc-ui-both');
wp_deregister_style('wpbc-ui-both');
wp_dequeue_style('wpbc-time_picker');
wp_deregister_style('wpbc-time_picker');
wp_dequeue_style('wpbc-time_picker-skin');
wp_deregister_style('wpbc-time_picker-skin');
wp_dequeue_style('wpbc-client-pages');
wp_deregister_style('wpbc-client-pages');
wp_dequeue_style('wpbc-fe-form_fields');
wp_deregister_style('wpbc-fe-form_fields');
wp_dequeue_style('wpbc-calendar');
wp_deregister_style('wpbc-calendar');
wp_dequeue_style('wpbc-calendar-skin');
wp_deregister_style('wpbc-calendar-skin');
wp_dequeue_style('wpbc-flex-timeline');
wp_deregister_style('wpbc-flex-timeline');
}
add_action('wp_enqueue_scripts', 'remove_booking_plugin_styles', 20);
If de-queuing and de-registering styles aren’t working as expected, an alternative is to directly filter the HTML output to remove the specific <link>
tags for the stylesheets. The following solution utilizes output buffering to accomplish this.
function remove_booking_plugin_styles_output() {
// Start output buffering and modify the final output
ob_start(function ($buffer) {
// Define the patterns to match the stylesheet <link> tags
$patterns = [
'/<link[^>]*id=\'wpdevelop-bts-css\'[^>]*>/i',
'/<link[^>]*id=\'wpdevelop-bts-theme-css\'[^>]*>/i',
'/<link[^>]*id=\'wpbc-tippy-popover-css\'[^>]*>/i',
'/<link[^>]*id=\'wpbc-tippy-times-css\'[^>]*>/i',
'/<link[^>]*id=\'wpbc-material-design-icons-css\'[^>]*>/i',
'/<link[^>]*id=\'wpbc-ui-both-css\'[^>]*>/i',
'/<link[^>]*id=\'wpbc-time_picker-css\'[^>]*>/i',
'/<link[^>]*id=\'wpbc-time_picker-skin-css\'[^>]*>/i',
'/<link[^>]*id=\'wpbc-client-pages-css\'[^>]*>/i',
'/<link[^>]*id=\'wpbc-fe-form_fields-css\'[^>]*>/i',
'/<link[^>]*id=\'wpbc-calendar-css\'[^>]*>/i',
'/<link[^>]*id=\'wpbc-calendar-skin-css\'[^>]*>/i',
'/<link[^>]*id=\'wpbc-flex-timeline-css\'[^>]*>/i'
];// Remove all matching <link> elements from the HTML output
$buffer = preg_replace($patterns, '', $buffer);
return $buffer;
});
}
// Hook the output buffer function to the wp_head and wp_footer actions
add_action('wp_head', 'remove_booking_plugin_styles_output', 1);
add_action('wp_footer', function () {
ob_end_flush(); // End buffering and flush the content to the browser
}, 100);
Could you provide me solution with wp_dequeue_style?