From e63a901c6b8a35722606d633a3e9149d15cacdaf Mon Sep 17 00:00:00 2001 From: Aadil Ayub Date: Thu, 10 Apr 2025 11:25:25 +0500 Subject: [PATCH] stage custom.css better --- functions.php | 58 +++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 49 insertions(+), 9 deletions(-) diff --git a/functions.php b/functions.php index e4dbb6a..1b92b33 100644 --- a/functions.php +++ b/functions.php @@ -7,17 +7,57 @@ function disable_default_patterns() add_action('after_setup_theme', 'disable_default_patterns'); -function somos_infinitos_custom_css() { - if ( ! is_admin() || is_customize_preview() ) { - wp_enqueue_style( - 'my-custom-style', - get_template_directory_uri() . '/assets/css/custom.css', - array(), - '1.0' - ); +/** + * Enqueue custom CSS file in block editor only + */ +function somos_infinitos_block_editor_styles() { + // Only load in block editor, not in classic editor + if (!is_classic_editor_active()) { + wp_enqueue_style( + 'somos-infinitos-block-editor-styles', + get_template_directory_uri() . '/assets/css/custom.css', + array(), + '1.0' + ); } } -add_action( 'enqueue_block_assets', 'somos_infinitos_custom_css' ); +add_action('enqueue_block_editor_assets', 'somos_infinitos_block_editor_styles'); + +/** + * Check if classic editor is active + */ +function is_classic_editor_active() { + // Check if the classic editor plugin is active + if (class_exists('Classic_Editor')) { + return true; + } + + // Check if we're on the classic editor screen + if (function_exists('get_current_screen')) { + $screen = get_current_screen(); + if ($screen && $screen->is_block_editor() === false && $screen->base === 'post') { + return true; + } + } + + return false; +} + +/** + * Enqueue custom CSS file on the frontend + */ +function somos_infinitos_frontend_styles() { + // Don't load in admin + if (!is_admin()) { + wp_enqueue_style( + 'somos-infinitos-custom-styles', + get_template_directory_uri() . '/assets/css/custom.css', + array(), + '1.0' + ); + } +} +add_action('wp_enqueue_scripts', 'somos_infinitos_frontend_styles'); // enable svg uploads add_filter('wp_check_filetype_and_ext', function ($data, $file, $filename, $mimes) {