繁体   English   中英

CSS JS 未在 wordpress 中更新

[英]CSS JS not updating in wordpress

我正在使用 WordPress 并致力于儿童主题。 我在子主题的资产文件夹中添加了一个 custom.css 文件。 并在 assets 文件夹中添加了一个文件夹 js,并添加了一个脚本文件 custom_script.js。 第一次测试时,我在 css 中添加了警报和一些体型。 运行良好,但一段时间后,我从这些文件中删除了所有内容,但没有更新,也没有添加新内容。 请检查是什么问题。 提前致谢。 网站是https://mealsgroupuk.com/

这里是子主题 function.php

<?php
// // Exit if accessed directly
if ( !defined( 'ABSPATH' ) ) exi
 // BEGIN ENQUEUE PARENT ACTION
 // AUTO GENERATED - Do not modify or remove comment markers above or below:

if ( !function_exists( 'chld_thm_cfg_parent_css' ) ):
function chld_thm_cfg_parent_css() {
    wp_enqueue_style( 'chld_thm_cfg_parent', trailingslashit( get_template_directory_uri() ) . 'style.css', array( 'iconmoon','bootstrap','bootstrap-theme','chosen','swiper' ) );
}
endif;
add_action( 'wp_enqueue_scripts', 'chld_thm_cfg_parent_css', 1 );

// END ENQUEUE PARENT ACTION



/* Enqueues the external CSS file */
add_action( 'wp_enqueue_scripts', 'custom_external_styles' );
function custom_external_styles() {

wp_register_style( 'custom-css', get_stylesheet_directory_uri().'/assets/custom.css' );
wp_enqueue_style( 'custom-css' );

}

/* Enqueues the external js file */
function my_scripts_method() {
wp_enqueue_script(
    'custom-script',
    get_stylesheet_directory_uri() . '/assets/js/custom_script.js',
    array( 'jquery' )
);
}

add_action( 'wp_enqueue_scripts', 'my_scripts_method' );

子主题> 资产 > custom.css

子主题> 资产 > js > custom_script.js

现在这两个文件都是空白的,但显示的是旧内容。

可能是版本(入队)的缓存问题。 您可以更改版本或简单地使用 time() 每次都获取最新版本。

wp_enqueue_script(
   'custom-script',
    get_stylesheet_directory_uri() . '/assets/js/custom_script.js',
    array('jquery'),
    time()
);

不要忘记在生产中替换 time() (使用主题或插件版本)以获得浏览器和服务器缓存的好处。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM