After a child theme is made how can I connect another child css file? So for example, currently only the style.css file in the child theme is working. But If I create another file called “cta-bar.css” and drag and drop it into my child theme folder, the css in that new file cta-bar,css that I just created, is not taking effect which means its not connected? where do I need to import or connect this new file so my theme recognizes it like it recognizes the current child style.css file ?
Hi There,
Thanks for writing in! You can refer to the following resource (https://digwp.com/2016/01/include-styles-child-theme/).
Hope that helps.
Hi I am still a little confused.
I see that my child themes functions file already has by default:
// Enqueue Parent Stylesheet
// =============================================================================
add_filter( 'x_enqueue_parent_stylesheet', '__return_true' );
Now that article says I am supposed to add something like this to my Child Functions.php file:
// Enqueue styles for child theme
// =============================================================================
function child_enqueue_styles() {
// enqueue parent styles
wp_enqueue_style('parent-theme', get_template_directory_uri() .'/style.css');
// enqueue child styles
wp_enqueue_style('child-theme', get_stylesheet_directory_uri() .'/style.css', array('parent-theme'));
}
add_action('wp_enqueue_scripts', 'child_enqueue_styles');
But like I said before, this theme already include the parent part by default? I dont want to mess the functions file up so I just want to check what am I supposed to change to connect another styles.css file in my child theme, like in my example lets call the second child css style sheet “cta-bar.css” ? How would i write that above function correctly ?
Hi There,
This is the only way to add a CSS file to the child theme.
// Enqueue styles for child theme
// =============================================================================
function child_enqueue_styles() {
// enqueue child styles
wp_enqueue_style('child-theme', get_stylesheet_directory_uri() .'/style.css', array('parent-theme'));
}
add_action('wp_enqueue_scripts', 'child_enqueue_styles');
Thanks
The File I am trying to add I named “cta-bar.css”
I added this to my child themes function.php file:
// Enqueue styles for child theme
// =============================================================================
function child_enqueue_styles() {
// enqueue child styles
wp_enqueue_style('child-theme', get_stylesheet_directory_uri() .'/cta-bar.css', array('parent-theme'));
}
add_action('wp_enqueue_scripts', 'child_enqueue_styles');
But it did not work because the css I have in cta-bar.css is not taking effect??
Hello There,
Is izaguir.re
the site in questioned? It seems that you are using a caching plugin. Please clear the cache and regenerate the minified js/css files so that your changes will take place. Caching plugins are best to turn on only when you’ve finished building the site.
Please let us know how it goes.
Hi Yes Izaguir.re is the website. I purged the cache and even deactivated the cache plugin and it still wont work. Would you like my login information? Thank you for your help
Hey There,
Yes please provide us the url of your site with login credentials so we can take a closer look?
To do this, you can create a secure note with the following info:
– Link to your site
– WordPress Admin username / password
Thank you.
Awesome thank you ,
Please tell me what you fix so I can learn how to add another style sheet in the future on my own
Hi,
I change the code from
wp_enqueue_style('child-theme', get_stylesheet_directory_uri() .'/cta-bar.css', array('parent-theme'));
to
wp_enqueue_style('child-theme', get_stylesheet_directory_uri() .'/cta-bar.css', array());
I then view source to check if the style is loading.
Please check in your end.
Thanks
This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.