简体   繁体   English

如何正确加载我的 custom.css 文件?

[英]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_cssstyle-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.

相关问题 我的custom.css文件显示与ssl和非ssl网址magento 2不同 - my custom.css file showing different with ssl and non-ssl urls magento 2 我的Joomla模板正在使用JS加载我的自定义CSS。 有没有一种方法可以将唯一的版本标签添加到我的自定义CSS中? 即:custom.css?20180101 - My Joomla Template is loading my custom CSS using JS. Is there a way to add the unique version tag to my custom CSS? i.e: custom.css?20180101 在wordpress中写入custom.css - Write to custom.css in wordpress PHP里面<link href=“css/custom.css” rel=“stylesheet”> - PHP inside an <link href=“css/custom.css” rel=“stylesheet”> 如何在imagestring()中加载我的自定义字体? - How Can I Load My Custom Font in imagestring()? 如何在 codeigniter 4 中加载 css 或 js 文件? - How can I load css or js file in codeigniter 4? 为什么在Moodle主题的“干净”中更改custom.css不起作用? - Why change of custom.css in “clean” of Moodle theme is not working? 如何将我的外部css文件包含在我的插件中 - How can i include my external css file to my plugin 每个会话如何加载一次CSS文件? - How can I load a CSS file once per session? 如何在自定义模块中的activecollab中链接CSS文件? - how can I link css file in activecollab in a custom module?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM