Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Wordpress child theme style.css not working

Tags:

I have created a file structure in the same format as my parent theme. My parent theme is called Alpine and within Alpine there is a functions.php and style.css file. There do not appear to be any additional style.css files.

I have created a directory called Alpine-child and within that I have created a functions.php and style.css file.

I can't work out why any changes I make to the child style.css are not implemented but they are when I make the same changes in parent style.css

This is my child style.css:

/*   Theme Name:   Alpine Child   Theme URI:    http://www.creative-ispiration.com/wp/alpine/   Description:  My first child theme, based on Alpine   Author:       MilkshakeThemes   Author URI:   http://themeforest.net/user/milkshakethemes   Template:     Alpine   Version:      1.0.0   Tags: one-column, two-columns, right-sidebar, fluid-layout, custom-menu, editor-style, featured-images, post-formats, rtl$   Text Domain: alpine-child  */

This is my child functions.php file:

<?php  add_action( 'wp_enqueue_scripts', 'my_theme_enqueue_styles' );  function my_theme_enqueue_styles() {      wp_enqueue_style( 'parent-style', get_template_directory_uri() . '/style.css' );  }  ?>
like image 986
Gavin Reynoldson Avatar asked Oct 11 '16 10:10

Gavin Reynoldson


People also ask

Why is my WordPress CSS not working?

Regenerating CSS: This can easily be fixed by going to WP admin > Elementor > Tools > Regenerate CSS. Then, you can clear the cache (WP cache and browser cache) and refresh the page. Clearing Site Cache: Check if you have any caching plugins on your site or any server level caching enabled. Clear those caches.

How do I add a custom CSS to my WordPress child theme?

No matter what WordPress theme you use, you can tweak CSS with the built-in theme customizer. Navigate to Appearance -> Customize section of your dashboard, scroll down to the bottom of the page and click Additional CSS. This will open an in-built tool that will allow you to add any CSS code.

How do you enqueue a child theme in CSS?

The recommended way of enqueuing the stylesheets is to add a wp_enqueue_scripts action and use wp_enqueue_style() in your child theme's functions.

How do I make a child theme in CSS?

css file, you can add the following code to your child theme's functions. php file: // enqueue styles for child theme // @ https://digwp.com/2016/01/include-styles-child-theme/ function example_enqueue_styles() { // enqueue parent styles wp_enqueue_style('parent-theme', get_template_directory_uri() . '/style.


1 Answers

Take a look at your <head> tag. More importantly look at the order of your stylesheets.

The styles from your child theme are being added first and then all the styles from your parent theme. This will cause the styles from the parent theme to override your child theme styles.

You can change the priority of your my_theme_enqueue_styles function to run after the parent by using the third parameter of add_action. This will enqueue your child theme styles last and allow the CSS to work as expected.

<?php add_action( 'wp_enqueue_scripts', 'my_theme_enqueue_styles', 11 ); function my_theme_enqueue_styles() {     wp_enqueue_style( 'child-style', get_stylesheet_uri() ); } ?> 
like image 100
Jrod Avatar answered Oct 05 '22 23:10

Jrod