Created child theme, have style and function files but style not working

I have created a my child theme, and have the style.css and functions.php files with the code below, but cant for the life of me get the css to work on the site.

My parent theme is startright and my child theme is startright-child

style.css

/*
Theme Name:     StartRight Child Theme
Theme URI:      http://isimrs.com/startright-child/
Description:    StartRight Child Theme
Author:         Accend4Web
Author URI:     http://www.accend4web.co.uk
Template:       startright
Version:        1.1.1
*/


.startright-header-main {
background-color: #000 !important;
}

Functions.php

<?php
function startright_enqueue_styles() {	
// enqueue parent styles
wp_enqueue_style('startright', get_template_directory_uri() .'/style.css');	
}
add_action('wp_enqueue_scripts', 'startright_enqueue_styles');
?>

In the theme editor I can see these child files, but that first and one css change isnt coming through, and cant get any css i add to the child stylesheet to work

This is the site - https://isimrs.com/

I’m looking at that child theme’s style.css and your startright-header-main is missing the period in front of it .startright-header-main that denotes that it’s a class selector.

Add the period and it works, for me.

Hi, I thought then that was going to be the most embarrasing shout for help I have ever done, but in a way thankfully I added the class selector and still nothing.

So am still here with this at the moment.

/*
Theme Name:     StartRight Child Theme
Theme URI:      http://isimrs.com/startright-child/
Description:    StartRight Child Theme
Author:         Accend4Web
Author URI:     http://www.accend4web.co.uk
Template:       startright
Version:        1.1.1
*/

/*@import url("../startright/style.css");*/

/* =Theme customization starts here
 ------------------------------------------------------- */

.startright-header-main {
background-color: #000 !important;
}


<?php
function startright_enqueue_styles() {	
// enqueue parent styles
wp_enqueue_style('startright', get_template_directory_uri() .'/style.css');	
}
add_action('wp_enqueue_scripts', 'startright_enqueue_styles');
?>

It’s working fine now, you might need to flush your cache?

Also, don’t be afraid of embarrassing mistakes, everyone here has probably (I know i have) made too many to count. Forgotten semicolons and the like :laughing:

3 Likes

Did you remember to also enqueue your child theme’s CSS file? See the WP codex for the instructions here.

2 Likes

@WebMachine I was assuming that the shown functions.php is from the child theme (must be, as the style change is working right now).

@multichild ? Get it working yet? If not, what browser and OS are you on

You can also try Private mode on Firefox or Incognito on Chrome, those load pages without cache/cookies/etc.

But yeah, looks fine (black background on that div) now, to me.

1 Like

Hi guys,

Thanks for the heads up with the enqueue for the css file, so looked into it and kept having the same issue, which was it took ages for the change in the css file to update on the website, so put it down to server cache. I then found a bit of code, used it and hey presto all worked fine, the changes where instant.

<?php
add_action( 'wp_enqueue_scripts', 'enqueue_child_theme_styles', PHP_INT_MAX);
function enqueue_child_theme_styles() {
wp_enqueue_style( 'startright', get_template_directory_uri().'/style.css' );
wp_enqueue_style( 'startright-child', get_stylesheet_uri(), NULL, filemtime( get_stylesheet_directory() . '/style.css' ) );
}
?>

It all came down to adding that filemtime line

2 Likes

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.