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.
CodePudding user response:
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()
orget_template_directory_uri()
to refer to the parent theme pathget_stylesheet_directory
orget_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.
CodePudding user response:
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');