2017-03-08 68 views
-1

嘿大家我嘗試了以下方法無濟於事。style.css在自定義創建的WordPress主題中沒有被調用?

首先

<?php 
    wp_head(); 
    wp_enqueue_style("style.css",get_template_directory_uri()); 
?> 

<?php 
    wp_head(); 
    wp_enque_style("style.css",get_stylesheet_uri()); 
?> 

<?php 
    wp_head(); 
    function my_assets() { 
     wp_enqueue_style('style' , get_template_directory_uri() .'/style.css'); 
    } 

    add_action('wp_enqueue_scripts', 'my_assets'); 
    do_action("wp_enque_scripts"); 
?> 

目錄結構

hospital_theme[ 
    style.css 
    index.php 
    header.php 
    footer.php 
    sidebar.php 
] 

主題是自定義用戶創建,它是從HTML文件轉換爲WordPress主題。目前主題只包含5個文件,即header.php,footer.php,sidebar.php,index.php,style.css。

我已經使用get_header(),get_footer()成功調用各個文件的內容。

回答

1

我們創建了一個在主題目錄中稱爲functions.php新文件。 請functions.php

function wpdocs_theme_name_scripts() { 
    wp_enqueue_style('style-name', get_stylesheet_uri().'/style.css'); 
} 

add_action('wp_enqueue_scripts', 'wpdocs_theme_name_scripts'); 
+0

試過了不行 – phpNoob

-1

在WP管理員:外觀>編輯> header.php文件,把簡單的HTML <link src=""...>
My print Screen

1

輸入以下代碼中有添加CSS另一種方式。您可以在header.php文件中添加以下代碼。

<link href="<?php echo get_template_directory_uri(); ?>/style.css" type="text/css" rel="stylesheet"> 
0

您可以使用下面的代碼。他們通常使用這個代碼在header.php文件中加載。

<link rel="stylesheet" type="text/css" media="all" href="<?php bloginfo('stylesheet_url'); ?>" /> 

希望它適用於您。