如何在wordpress中链接外部css


How to link external css in wordpress?

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

最好的选择是将文件排队到所需的页面上。

在 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

您可以使用

排队,也可以转到主题的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">