2016-05-23 14 views
0

私が開発しようとしているワードプレスのテーマにstyles.cssスタイルシートを含めることを試みています(私の最初のもの)。質問:どのようにそれを含めて行くだろうか?まだこのdoewがまったく機能していないwordpressテーマにstyles.cssを含めるには?

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

:しかし、私はむしろ、そうのようなのfunctions.phpを通してそれを含めたい

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

:私は働く私のheader.phpのファイルに次のコードを置くことを知っています(私は私のheader.phps「頭」から行を削除すると、私のスタイルが見られない?

+1

https://codex.wordpress.org/Plugin_API/Action_Reference/wp_head <?PHPの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をファイルを含めるための最良の方法を追加することですあなたのテーマの次のコードfunctions.php

あなたは `必要

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

関連する問題