Chappy Tabby

2 possible problem and troubleshooting for WordPress custom theme

Monitor showing programming language photo (from unsplash)
Home »  Blog » WordPress » 2 possible problem and troubleshooting for WordPress custom theme

How to disable ‘style.min.css’ (for WordPress version 5.x)

The CSS file ‘style.min.css‘ is a new stylesheet for Gutenberg block editor.
It possibly causes some conflict with your custom theme since it is loaded after CSS file made for your theme.

Solution

Use the function ‘wp_dequeue_style‘ in functions.php to prevent ‘style.min.css‘ from loading.

add_action('wp_enqueue_scripts', 'remove_block_library_style');
function remove_block_library_style() {
  wp_dequeue_style('wp-block-library');
  wp_dequeue_style('wp-block-library-theme');
}

Reference

https://smartwp.com/remove-gutenberg-css/

I noticed that there is ‘wp_dequeue_stype’ in opposition to ‘we_enqueue_style’.

How to replace the other version of jQuery on WordPress

WordPress uses jQuery by default, version 1.12.4.

FYI the latest version of jQuery is 3.4.1.

It may make some troubles if you use the script or library for the latest version jQuery.

Solution

First, disable the default jQuery by using functions ‘wp_dequeue_script’, then ‘wp_deregister_script‘ in functions.php.
Next, use ‘wp_enqueue_script‘ function to enable jQuery what you want to load.
Last, set ‘add_action’ function to load this script after default scripts.

add_action('wp_enqueue_scripts', 'load_scripts', 100);
function load_scripts(){
  wp_dequeue_script('jquery');
  wp_deregister_script('jquery');
  wp_enqueue_script('jquery', 'https://cdn.jsdelivr.net/npm/jquery@3.4.1/dist/jquery.min.js', false, null, true);
  wp_enqueue_script('jquery-scrollto', 'https://cdn.jsdelivr.net/npm/jquery.scrollto@2.1.2/jquery.scrollTo.min.js', false, null, true);
  wp_enqueue_script('ct-main-script', get_template_directory_uri() . '/js/main.js', false, null, true);
}

Reference

https://stackoverflow.com/questions/23507179/wp-dequeue-script-for-child-theme-to-replace-script

Inquire about WordPress

Related Posts

WordPress

»