如何在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">
http://stackoverflow.com/questions/11709625/is-using-import-declarations-a-bad-practice – 2014-11-20 17:25:42
是的,或者你可以编辑主题中的header.php文件以链接到外部样式表。 – Aibrean 2014-11-20 17:26:28
编辑的主题? – naththedeveloper 2014-11-20 17:21:03