Add Styles and Scripts to a WordPress child theme

Load WordPress scripts and styles the right way, by adding the following code to functions.php.

add_action( 'wp_enqueue_scripts', 'enqueue' );
function enqueue() {
    // stylesheet from the parent theme
    wp_enqueue_style( 'parent-style', get_template_directory_uri().'/style.css' );
    // child theme style.css
    wp_enqueue_style( 'child-style', get_stylesheet_uri() );
    // child theme css and scripts
    wp_enqueue_style( 'child-theme-style', get_stylesheet_directory_uri().'/css/theme.css' );
    wp_enqueue_script( 'child-theme-scripts', get_stylesheet_directory_uri().'/js/theme.js' );
?>Code language: HTML, XML (xml)

You may also find this this article helpful. Explaining how to create a basic WordPress child theme, that’s ready to be customised.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.