2016-05-23 102 views
0

我想包括我的styles.css样式表在wordpress主题我试图发展(我的第一个)。问题:如何包含它?我想想,把下面的代码在我的header.php文件的工作原理:如何在wordpress主题中包含styles.css?

<link rel="stylesheet" href="<?php bloginfo('stylesheet_url'); ?>"> 

但是我宁愿喜欢像这样把它列入通过的functions.php:

<?php 
function firstTheme_style(){ 
    wp_enqueue_style('core', 'style.css', false); 
} 
add_action('wp_enqueue_scripts', 'firstTheme_style'); 
?> 

然而,这doew不能工作(当我删除从我header.phps“头”行了,我的风格是没见过?

+1

https://codex.wordpress.org/Plugin_API/Action_Reference/wp_head你需要','在你的header.php – Steve

回答

4

以下方法是包括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'); 
+1

真棒,对不起,noobish问题来:当你说到网站前端时,这是否也意味着在functions.php文件中? –

+1

**方法1 **您必须将代码插入到活动主题的“header.php”文件中。 **方法2 **和**方法3 **代码可以插入活动主题'functions.php'文件 – purvik7373

0

,包括您的styles.css文件的最佳方法是添加以下代码在您的主题功能.php

function themename_enqueue_style() { wp_enqueue_style('themename-style', get_stylesheet_uri()); } add_action('wp_enqueue_scripts', 'themename_enqueue_style');