zoukankan      html  css  js  c++  java
  • 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();?>
  • 相关阅读:
    gcc各个版本下载
    加减法运算解决乘除法
    蚂蚁碰撞的概率
    ns2.34移植leach协议
    ubantu16.04安装ns2.34 错误
    ubantu安全卸载火狐浏览器
    post和get的区别
    docker加速配置阿里云镜像
    重装系统后,会因为本机保存的公匙不对报错
    集合 set
  • 原文地址:https://www.cnblogs.com/tinyphp/p/6439928.html
Copyright © 2011-2022 走看看