簡體   English   中英

無法找出我的functions.php出了什么問題?

[英]Can't figure out what is wrong with my functions.php?

我想要附加stye.css,以便可以看到wordpress主題中的更改,但是我的網站上沒有CSS。 我不知道這里是什么錯誤。

<?php

function learningWordPress_resources() {

  wp_enqueue_style('style', get_stylesheet_uri() );

}

add_action('wp_enqueue_style', 'learningWordPress_resources');

首先css的路徑在哪里

<?php

function learningWordPress_resources() {

  /*wp_enqueue_style('style', get_stylesheet_uri() );*/

 // get the directory of your theme location and add the path of css
  wp_enqueue_style('style',get_template_directory_uri().'/css/style.css');

}

//add_action('wp_enqueue_style', 'learningWordPress_resources');
   /*
     * replace wp_enqueue_style with wp_enqueue_script
  */
  add_action('wp_enqueue_scripts','learningWordPress_resources');

另一種解決方案在header.php文件中添加樣式文件

<link href="<?php bloginfo('stylesheet_directory');?>/css/style.css" rel="stylesheet" />

為了根據文件的最后修改時間進行正確的版本控制,可以使用類似於以下內容的東西:

wp_enqueue_style('main-styles', get_template_directory_uri() . '/css/style.css', array(), filemtime(get_template_directory() . '/css/style.css'), false);

在服務器上更新style.css文件時,WP將附加適當的時間戳。

注意:永遠不要使用time()作為第四個參數或將其附加到文件中,因為這幾乎在所有情況下都會中斷緩存。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM