【问题标题】:How i can load a CSS file in my wordpress theme head tag [duplicate]我如何在我的 wordpress 主题头标签中加载 CSS 文件 [重复]
【发布时间】:2016-10-26 23:47:08
【问题描述】:

我是 WordPress 新手。我有一个链接,我想在我的 WordPress 主题的 head 标签中添加

<link rel="stylesheet" href="http://pashtofonts.com/api/pashto.css" />

请有人帮助我以一种简单的方式将此 CSS 链接添加到我的 WordPress 主题中。

我看过其他例子,但无法理解。

【问题讨论】:

    标签: css wordpress


    【解决方案1】:

    执行此操作的最佳方法是将脚本从函数文件中排入队列。

    只需将下面的行添加到主题目录中functions.php 文件的底部即可。

    function my_style_sheets() {
        wp_enqueue_style( 'pashto-font-css', 'http://pashtofonts.com/api/pashto.css' );
    }
    add_action( 'wp_enqueue_scripts', 'my_style_sheets' );
    

    这将确保您的普什图样式表与您的网站使用的所有其他样式表一起加载到网页的 HTML 头部。

    【讨论】:

    • 谢谢你帮助我
    【解决方案2】:

    如果你想把 css 放在你的 head 标签中,这会很好。

        <link rel="stylesheet" href="http://pashtofonts.com/api/pashto.css" />
    

    但这不是一个好习惯。在你的functions.php中编写以下函数

    function resources(){
    
      wp_enqueue_style('pashto',http://pashtofonts.com/api/pashto.css',array());
    }
    add_action('wp_enqueue_scripts','resources');
    }
    

    【讨论】:

      【解决方案3】:

      包含 css 文件的最简单方法是将下面提到的行粘贴到 wordpress 主题的 header.php 文件中,然后将 css 文件粘贴到同一文件中

      【讨论】:

        猜你喜欢
        • 2019-11-21
        • 2019-06-23
        • 1970-01-01
        • 1970-01-01
        • 2017-06-15
        • 2018-10-28
        • 1970-01-01
        • 2013-12-24
        • 2017-11-18
        相关资源
        最近更新 更多