skip to Main Content

I am creating a wordpress theme and my styles queue is not working.

This is the queue in functions.php

function style_script_enqueue(){
   wp_enqueue_style('main-styles', get_template_directory_uri() . '/css/main.css' );
   wp_enqueue_style('responsive-styles', get_template_directory_uri() . 
   '/css/responsive.css' );
   wp_enqueue_script('custom_script', get_template_directory_uri() . '/js/script.js', array(), '1.0.0', true);
}
add_action('wp_enqueue_scripts', 'style_script_enqueue');

I have also called wp_head(); , wp_footer(); , and checked the directory.

2

Answers


  1. Do you want to enqueue your CSS/JS in a child theme derived from another existing theme? Unless you build your own theme from scratch, child themes are the preferred practice to extend existing themes (update safe).

    If you are in a child theme, there are two functions you might want to consider:

    • get_template_directory() or get_template_directory_uri() to refer to the parent theme path
    • get_stylesheet_directory or get_stylesheet_directory_uri() to refer to the child theme path

    PS.: You might want to check if there are multiple functions registered for wp_enqueue_scripts, which try to enqueue CSS/JS with the identical name. If so, try to alter main-styles, responsive-styles, custom_script or the optional priority parameter for add_action as described in the function documentation.

    Login or Signup to reply.
  2. Its work for me.

    function add_css_js(){
    
    // Load css 
    
    wp_enqueue_style('style',get_template_directory_uri().'/assets/css/style.css',array(),'1.0.0','all'); 
        
    //load JS
    
    wp_enqueue_script('bootstrap',get_template_directory_uri().'/assets/js/bootstrap.min.js',array('jquery'),'1.0.0',true);
    
    }add_action('wp_enqueue_scripts','add_css_js');
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search