这就是我添加样式和脚本的方式对我来说非常有用。但我建议在使用它之前先了解它,然后任何人都可以按照自己的方式遵循这种方法。
function theme_files() {
$styles = [
['handle' => 'style', 'src' => '../style.css', 'deps' => false, 'media'=>"all"],
['handle' => 'bootstrap', 'src' => 'bootstrap.min.css', 'deps' => false, 'media'=>"all"],
['handle' => 'font_awesome', 'src' => 'font-awesome.min.css', 'deps' => false, 'media'=>"all"],
['handle' => 'animate', 'src' => 'animate.min.css', 'deps' => false, 'media'=>"all"],
['handle' => 'lightbox', 'src' => 'lightbox.css', 'deps' => false, 'media'=>"all"],
['handle' => 'main', 'src' => 'main.css', 'deps' => false, 'media'=>"all"],
['handle' => 'responsive', 'src' => 'responsive.css', 'deps' => false, 'media'=>"all"]
];
for ($i = 0; $i < sizeof($styles); $i++) {
wp_enqueue_style($styles[$i]['handle'], get_template_directory_uri() . '/css/' . $styles[$i]['src'], $styles[$i]['deps'], $styles[$i]['media'] );
}
$scripts = [
['handle' => 'bootstrap', 'src'=>'bootstrap.min.js','dep'=> array( 'jquery' ),'var'=> false,'in_foot'=> true],
['handle' => 'lightbox', 'src'=>'lightbox.min.js','dep'=> array( 'jquery' ),'var'=> false,'in_foot'=> true],
['handle' => 'wow', 'src'=>'wow.min.js','dep'=> array( 'jquery' ),'var'=> false,'in_foot'=> true],
['handle' => 'main', 'src'=>'main.js', 'dep'=>array( 'jquery' ), 'var'=>false, 'in_foot'=>true]
];
for ($i=0; $i < sizeof($scripts); $i++) {
wp_enqueue_script( $scripts[$i]['handle'], get_template_directory_uri() . '/js/' . $scripts[$i]['src'], $scripts[$i]['dep'], $scripts[$i]['ver'], $scripts[$i]['in_foot'] );
}
}
add_action( 'wp_enqueue_scripts', 'theme_files' );