0

It's my first time working with WordPress. I have created a child theme in order to style a footer better.

I've added custom style to style.css and it worked great until it didn't. Now, all of a sudden, it doesn't load any changes I make to style.css.

I have even deleted style.css and nothing changed.

How can I fix it ? I've cleared my cache, I've reloaded using CTRL+F5. This is localhost on XAMPP.

I can't clear the cache every time I make a change to style.css and I will make a lot of changes to style.css until the website is finished.

This is my functions.php:

<?php
// add_action( 'wp_enqueue_scripts', 'enqueue_parent_styles' );
// function enqueue_parent_styles() {
//    wp_enqueue_style( 'parent-style', get_template_directory_uri().'/style.css' );
// }

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

I have found this answer: https://wordpress.stackexchange.com/a/173076/198154

But I have no idea where to put the code:

<?php
$file = get_bloginfo( 'stylesheet_url' )
    . '?' . filemtime( get_stylesheet_directory() . '/style.css' );
?>
<link rel="stylesheet" href="<?php echo $file; ?>" type="text/css" />

In what file does that go ?

1 Answer 1

0

Try this:

function enqueue_child_theme_styles() {
    wp_enqueue_style( 'parent-style', get_template_directory_uri() . '/style.css' );
    wp_enqueue_style( 'child-style', get_stylesheet_uri() . '?v=' . filemtime( get_stylesheet_directory() . '/style.css' ) );
}
10
  • Should I replace all I've got in functions.php with that ?
    – Jorje12
    Commented Nov 27, 2020 at 11:20
  • No, it is only a new version of enqueue_child_theme_styles function. Keep the add_action and others untouched. Commented Nov 27, 2020 at 11:21
  • Nope. It still doesn't update the style. Can you please edit your answer and type in exactly what I should have inside functions.php ? That would really help. Thank you.
    – Jorje12
    Commented Nov 27, 2020 at 11:23
  • I've even deleted style.css and nothing happens. How is this possible ?
    – Jorje12
    Commented Nov 27, 2020 at 11:30
  • This definitely looks like the style is still served from the cache. I'd rather add something like Pragma: no-cache header via the Apache config to prevent any caching of development version. Commented Nov 27, 2020 at 11:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.