How to properly enqueue css and javascript file in pro

I’m using child theme and would like to know if there are examples how to enqueue css and javascript file in front end of my site. For example I want to try this code to include a simple css file:

wp_register_style(
    'slick-main-style', // handle name
    get_template_directory_uri() . '/slick-180/slick/slick.css', // the URL of the stylesheet
    //array('bootstrap-main'), // an array of dependent styles
    null,
    '1.8.0', // version number
    'screen', // CSS media type
);
wp_enqueue_style( 'slick-main-style' );

Is there something that I should add regarding x pro? Should I consider which stack is active etc.
Please consider that I want to avoid using a plugin.
Thank you in advance.

Hi There,

You should try with this code:

function x_theme_name_scripts() {
    wp_enqueue_style( 'style-name', get_template_directory_uri() . '/css/example.css' );
    wp_enqueue_script( 'script-name', get_template_directory_uri() . '/js/example.js', array('jquery'), '1.0.0', true );
}
add_action( 'wp_enqueue_scripts', 'x_theme_name_scripts' );

The code above should be added under functions.php locates in your child theme.

Regards!

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.