Hi,
I’m using a trick I got from here to load only my custom js in the front side on the website. I didn’t want it to load when I’m editing the page with cornerstone.
I’d like to do the same with style. So, I’m using the following function but the style is loaded anyway. Am I missing something? It’s working with script with this function but not with style.
function custom_scripts()
{
wp_register_style('theme-styles', get_stylesheet_directory_uri() . '/style.css', array(), filemtime(get_stylesheet_directory() . '/style.css'), true);
if (!isset($_POST['cs_preview_state']) || !$_POST['cs_preview_state'] || 'off' === $_POST['cs_preview_state']) {
wp_enqueue_style('theme-styles');
} else {
wp_dequeue_style('theme-styles');
}
wp_register_script('custom-script', get_stylesheet_directory_uri() . '/custom.js', array(), filemtime(get_stylesheet_directory() . '/custom.js'), true);
if (!isset($_POST['cs_preview_state']) || !$_POST['cs_preview_state'] || 'off' === $_POST['cs_preview_state']) {
wp_enqueue_script('custom-script');
} else {
wp_dequeue_script('custom-script');
}
}
add_action('wp_enqueue_scripts', 'custom_scripts', 99);
Also, I just noticed it’s loaded twice oO
<link rel='stylesheet' id='x-child-css' href='https://coldpartner.fr/wp-content/themes/pro-child/style.css?ver=3.0.3' type='text/css' media='all' />
<link rel='stylesheet' id='theme-styles-css' href='https://coldpartner.fr/wp-content/themes/pro-child/style.css?ver=1572130475' type='text/css' media='1' />