WordPress – How to enqueue script to child theme?

To enqueue script in a Child Theme do the following –

In WordPress, when working with a child theme, you should use get_stylesheet_directory_uri() instead of get_template_directory_uri() when enqueuing styles or scripts to ensure that you’re referencing files from the child theme directory. If you use get_template_directory_uri(), it will reference the parent theme’s directory, which might not contain the files you want to enqueue. Here’s the corrected code:

wp_enqueue_style('owl-carousel', get_stylesheet_directory_uri() . '/assets/css/owl.carousel.min.css', array(), '1.0', 'all');

Make sure that the ‘owl-carousel’ handle and the file path ‘/assets/css/owl.carousel.min.css’ are correct for your child theme’s directory structure. Also, ensure that the file you’re trying to enqueue exists in the specified location.

After making this change, your child theme should correctly enqueue the Owl Carousel stylesheet. Don’t forget to check for any typos in the file path and handle name.

Related Posts –