繁体   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