如何在wordpress主题中包含styles.css? [英] How to include styles.css in wordpress theme?
本文介绍了如何在wordpress主题中包含styles.css?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试将我的styles.css样式表包含在我要开发的wordpress主题中(我的第一个主题).问题:如何将其包括在内?我知道将以下代码放入header.php文件中即可:
I am trying to include my styles.css stylesheet in a wordpress theme I am trying to develop (my first one). Question: How would one go about including it? I know putting the following code in my header.php file works:
<link rel="stylesheet" href="<?php bloginfo('stylesheet_url'); ?>">
但是我想像这样通过functions.php包含它:
however I would rather like to include it through functions.php like so:
<?php
function firstTheme_style(){
wp_enqueue_style( 'core', 'style.css', false );
}
add_action('wp_enqueue_scripts', 'firstTheme_style');
?>
但这根本不起作用(当我从header.phps'head'中删除该行时,看不到我的样式吗?
yet this doew not work at all (When i remove the line from my header.phps 'head', my styles are not seen?
推荐答案
以下方法包括style.css
.
方法-1
// add in your header.php
<link rel="stylesheet" href="<?php echo get_stylesheet_uri(); ?>">
方法-2
// load css into the website's front-end
function mytheme_enqueue_style() {
wp_enqueue_style( 'mytheme-style', get_stylesheet_uri() );
}
add_action( 'wp_enqueue_scripts', 'mytheme_enqueue_style' );
方法-3
// Add this code in your functions.php
function add_stylesheet_to_head() {
echo "<link href='".get_stylesheet_uri()."' rel='stylesheet' type='text/css'>";
}
add_action( 'wp_head', 'add_stylesheet_to_head' );
这篇关于如何在wordpress主题中包含styles.css?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文