Skip to content

Commit

Permalink
Prevent Customizer CSS from Loading on the frontend
Browse files Browse the repository at this point in the history
- Updated enqueue block editor to only add the custom css for block editor by adding is_admin()
- Added condition if option `loadCustomizerCSSFrontend` is false then remove wp_custom_css_cb where it add the custom css via frontend it also include in preview.
  • Loading branch information
FrancisBoundlessWorpdress committed Feb 9, 2024
1 parent 087dab0 commit 80892a6
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion php/Admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ public function run() {
if ( (bool) $options['loadCustomizerCSSBlockEditor'] ) {
add_action( 'enqueue_block_assets', array( $this, 'enqueue_customizer_css_block_editor' ), PHP_INT_MAX );
}
// Since by default wp_custom_css_cb is add_action wp_head, just remove_action.
if ( ! (bool) $options['loadCustomizerCSSFrontend'] ) {
remove_action('wp_head', 'wp_custom_css_cb', 101);

Check failure on line 63 in php/Admin.php

View workflow job for this annotation

GitHub Actions / WPCS

Expected 1 spaces after opening parenthesis; 0 found

Check failure on line 63 in php/Admin.php

View workflow job for this annotation

GitHub Actions / WPCS

Expected 1 spaces before closing parenthesis; 0 found
}
}


Expand Down Expand Up @@ -568,7 +572,7 @@ public function admin_page() {
*/
public function enqueue_customizer_css_block_editor() {
$custom_css = wp_get_custom_css();
if ( ! empty( $custom_css ) ) {
if ( ! empty( $custom_css ) && is_admin() ) {
wp_register_style(
'dlx-pw-customizer-css-block-editor',
false
Expand Down

0 comments on commit 80892a6

Please sign in to comment.