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();?>

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM