[英]how can I load my custom.css file properly?
custom.css file load properly but after some changes in CSS file and send it on filezilla it does not load that current changes. custom.css 文件正确加载,但在 CSS 文件进行一些更改并将其发送到 filezilla 后,它不会加载当前更改。 It loads after remove functions.php file and again paste all data.
它在删除 functions.php 文件后加载并再次粘贴所有数据。 What should I do to solve that problem.
我应该怎么做才能解决这个问题。 Below I have attached link file.
下面我附上了链接文件。 I also write
<?php wp-head()?>
in header and <?php wp-footer()?>
in footer file.我还写
<?php wp-head()?>
在 header 和<?php wp-footer()?>
在页脚文件中。
function wpdocs_theme_name_scripts() {
// style link
wp_enqueue_style ( 'bootstrap.min', get_template_directory_uri(). '/assets/css/bootstrap.min.css','1.1', true);
wp_enqueue_style ( 'swiper-bundle.min ', get_template_directory_uri(). '/assets/css/swiper-bundle.min.css','1.1', true);
wp_enqueue_style ( 'style css', get_stylesheet_uri() );
wp_enqueue_style ( 'custom css', get_bloginfo('template_directory'). '/custom.css','1.1', true);
// script link
wp_enqueue_script ( 'jquery-3.5.1.slim.min', get_template_directory_uri(). '/assets/js/jquery-3.5.1.slim.min.js', array(), 1.0, true );
wp_enqueue_script ( 'bootstrap.bundle.min', get_template_directory_uri(). '/assets/js/bootstrap.bundle.min.js', array(), 1.0, true);
wp_enqueue_script ( 'popper.min', get_template_directory_uri(). '/assets/js/popper.min.js', array(), 1.0 , true );
wp_enqueue_script ( 'swiper-bundle.min', get_template_directory_uri(). '/assets/js/swiper-bundle.min.js', array(), 1.0 , true );
wp_enqueue_script ( 'main js', get_stylesheet_directory_uri(). '/assets/js/main.js', array(), 1.0 , true );
};
add_action( 'wp_enqueue_scripts', 'wpdocs_theme_name_scripts' );
This sounds like a caching issue.这听起来像是一个缓存问题。 If you are not able to properly clear server's and browser's cache then you can have proper versioning based on the file's last modified time.
如果您无法正确清除服务器和浏览器的缓存,那么您可以根据文件的最后修改时间进行适当的版本控制。 Example:
例子:
$my_version = filemtime(get_template_directory() . '/custom.css');
wp_enqueue_style ('custom-css', get_template_directory() . '/custom.css', false, $my_version, 'all');
When the custom.css file is updated on the server, WP will append the appropriate timestamp and your browser will download the new version.当 custom.css 文件在服务器上更新时,WP 将为 append 提供适当的时间戳,您的浏览器将下载新版本。
Also do not use spaces in your handle strings, ie.也不要在句柄字符串中使用空格,即。 change
'custom css'
to 'custom-css'
.将
'custom css'
更改为'custom-css'
。
Using the third parameter, the array()
, upon enqueuing, you can define a dependency using the dependency handle, via the array( 'dependency_handle' )
.使用第三个参数
array()
在入队时,您可以通过array( 'dependency_handle' )
使用依赖句柄定义依赖。 Your dependency handle should be a one word string, you can't use style css
you need to use style_css
or style-css
.您的依赖句柄应该是一个单词字符串,您不能使用
style css
您需要使用style_css
或style-css
。
<?php
add_action( 'wp_enqueue_scripts', 'theme_scripts' );
function theme_scripts() {
if( ! is_admin() ) {
wp_enqueue_style ( 'style_css', get_stylesheet_uri(), array(), '1.0', 'all' );
wp_enqueue_style ( 'custom_css', trailingslashit( get_template_directory_uri() ) . 'custom.css', array( 'style_css' ), '1.0', 'all' );
};
}; ?>
Here we specify that we want out custom_css
to be enqueued AFTER the style_css
.在这里,我们指定我们希望在
custom_css
之后将style_css
加入队列。
Using the fourth parameter, the version, here 1.0
let Wordpress knows NOT to serve a cache version if the version as changed.使用第四个参数,版本,这里是
1.0
,让 Wordpress 知道如果版本改变,则不提供缓存版本。 Therefore if you specified 1.1
Wordpress will fetch a fresh version of our script.因此,如果您指定
1.1
Wordpress 将获取我们脚本的新版本。 (For development tho, you might want just to use your browser in incognito mode, which doesn't cache anything) (对于开发来说,您可能只想在隐身模式下使用浏览器,这不会缓存任何内容)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.