Defining CSS and JS (wp_enqueue_style) WordPress Theme – Part 3

 Defining CSS and JS (wp_enqueue_style) WordPress Theme – Part 3

When creating a theme, you may want to define CSS and JS files. However, remember that not only will your WordPress website be active, it will also use many different plugins. In order for everything to work harmoniously, it is important that themes and plugins load CSS and JS files using the standard WordPress method. This will ensure that the site remains functional and that there are no incompatibility issues.

Adding CSS and JS files to WordPress is a fairly simple process. Essentially, you’ll create a function that will list all your CSS and JS files. When queuing your CSS and JS files, WordPress creates a pointer and path to find your file and any dependencies it may contain (like jQuery)

Correct way to define CSS and JS files

 function wpmrj3_resources()
{
    wp_enqueue_style('style', get_stylesheet_uri());
}         
add_action'wp_enqueue_scripts', 'wpmrj3_resources');
function load_wpmrj3_resources_js()
                {
                wp_enqueue_script('jquery');
                    wp_register_script('site', get_template_directory_uri() . '/asst/site.js', 'jquery',false, true);
                    wp_enqueue_script('site');
                    wp_enqueue_script('jquery');
                    
                }
add_action ('wp_enqueue_scripts','load_wpmrj3_resources_js');