我正在使用WordPress,并致力于一个儿童主题。我在子主题的assets文件夹中添加了一个custom.css文件。和assets文件夹中的文件夹js,并添加了脚本文件custom_script.js。第一次测试时,我在css中添加了一个警告和一些正文样式。运行良好,但过了一段时间后,我从这些文件中删除了所有内容,但没有更新,也没有添加新内容。请检查一下isses是什么。提前谢谢。网站为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
现在,这两个文件都是空白的,但显示了旧内容。
发布于 2021-06-08 17:12:34
可能是版本(入队)的缓存问题。您可以更改版本,或者每次都使用time()来获取最新版本。
wp_enqueue_script(
'custom-script',
get_stylesheet_directory_uri() . '/assets/js/custom_script.js',
array('jquery'),
time()
);不要忘记在生产环境中替换time() (使用主题或插件版本),以获得浏览器和服务器缓存的好处。
https://stackoverflow.com/questions/67874520
复制相似问题