admin管理员组

文章数量:1314039

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:

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 ?

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/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 ?

Share Improve this question edited Nov 27, 2020 at 11:31 Jorje12 asked Nov 27, 2020 at 11:11 Jorje12Jorje12 1033 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 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' ) );
}

本文标签: csschildtheme style not changing on localhost