我正在研究一个遗留的 wp 主题,并且有一些我想应用到设置模板的可爱干净的新 CSS 和 js。
我已经设法使用下面的脚本从应用到我的新模板中删除了旧的 CSS 和 js。
但是,如何在删除旧的同时向这些函数添加新的脚本和样式?
例如,删除所有旧的 CSS 和 js 现在添加这些 js 和 CSS
/**
* Remove all java scripts.
*/
function se_remove_all_scripts() {
global $wp_scripts;
if ( is_page_template( 'new-template/page-main.php' ) ) {
$wp_scripts->queue = array();
}
}
/**
* Remove all style sheets.
*/
function se_remove_all_styles() {
global $wp_styles;
if ( is_page_template( 'new-template/page-main.php' ) ) {
$wp_styles->queue = array();
}
}
add_action( 'wp_print_styles', 'se_remove_all_styles', 99 );
add_action( 'wp_print_scripts', 'se_remove_all_scripts', 99 );