【问题标题】:How to link external css in wordpress? [closed]如何在wordpress中链接外部css? [关闭]
【发布时间】:2015-01-18 16:08:45
【问题描述】:

我使用的主题仅支持一个主标题菜单。我正在尝试使用另一个使用外部 css 来制作另一个。如何在 wordpress 主题中链接外部 css。

【问题讨论】:

    标签: php css wordpress web content-management-system


    【解决方案1】:

    您最好的选择是将文件排入您想要的页面。

    在functions.php文件中,添加这段代码

    // Register style sheet.
    add_action( 'wp_enqueue_scripts', 'register_custom_plugin_styles' );
    
    /**
     * Register style sheet.
     */
    function register_custom_plugin_styles() {
        wp_register_style( 'my-stylesheet', 'STYLESHEETS URL' );
        wp_enqueue_style( 'my-stylesheet' );
    }
    

    如果您只想在特定页面上执行此操作,那么您需要将它放在 if 语句中,检查您当前所在的页面以确定是否运行上述脚本。

    在此处阅读有关排队脚本的更多信息:http://codex.wordpress.org/Function_Reference/wp_register_style

    【讨论】:

      【解决方案2】:

      您可以使用 enqueue,也可以转到主题的 style.css 文件,然后在其中使用 @import 规则链接到。

      例子:

      @import url("//netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.css");
      

      或者,您可以编辑主题中的header.php 文件以链接到外部样式表。

      例子:

      <link href="//maxcdn.bootstrapcdn.com/font-awesome/4.2.0/css/font-awesome.min.css" rel="stylesheet">
      

      【讨论】:

      猜你喜欢
      • 2012-11-07
      • 1970-01-01
      • 2019-09-11
      • 2021-05-03
      • 1970-01-01
      • 2012-02-28
      • 2014-04-18
      • 2016-07-01
      • 1970-01-01
      相关资源
      最近更新 更多