WordPress主题开发:加载脚本和样式

如果只引入style.css,我把这个放头顶就可以了

 <link rel="stylesheet" href="<?php echo get_stylesheet_uri(); ?>" type="text/css" media="screen" />

再加其他样式,那就加多一个这个在头顶

  <link rel="stylesheet" href="<?php echo get_template_directory_uri();?>/bootstrap.min.css">

另外一种推荐的方法

把下面的方法加到functions.php

/**
* 加载前台脚本和样式表
* 加载主样式表style.css
*/
add_action('wp_enqueue_scripts', 'my_scripts');
function my_scripts() {
//加载主题中的style.css
wp_enqueue_style('global', get_stylesheet_uri());
//加载css文件夹中的xx.css样式 wp_enqueue_style('index-style', get_template_directory_uri().'/css/xx.css');

//同理加载js文件夹中的xx.js
wp_enqueue_script('index-js', get_template_directory_uri().'/js/xx.js');

//加载tool.js前加载默认jquery库
wp_enqueue_script('lingfeng-lazy',get_template_directory_uri().'/js/tool.js',array('jquery'));

}

然后在head里加上这个就会自动引入样式噢~

 <?php wp_head();?>
原文地址:https://www.cnblogs.com/tinyphp/p/6439928.html