在 WordPress 中导入 CSS 文件 [英] Import CSS files in WordPress

查看:33
本文介绍了在 WordPress 中导入 CSS 文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将我的 HTML 迁移到 WordPress 模板.当我这样做时,我想将我的 CSS 文件保留在它们所在的位置并将它们导入到代码中.我发现我可以使用 functions.php 文件来简化它.

I'm trying to migrate my HTML to WordPress template. While I'm doing that, I want to keep my CSS files where they are placed and import them to the code. I found out that I can use functions.php file to make it easier.

下面是我添加到functions.php的代码:

Below is the code that I added to functions.php:

<?php
function add_theme_codes() {     
 wp_enqueue_style(‘bootstrap’,get_stylesheet_directory_uri().’/css/bootstrap_grid.css’, ‘all’); 
 wp_enqueue_style( ‘style’, get_stylesheet_directory_uri().’/css/main.css’, ‘all’);
}
add_action( ‘wp_enqueue_scripts’, ‘add_theme_codes’ );
?>

但我的 WordPress 网站仍然没有导入 CSS 文件.

But still my WordPress site is not importing the CSS files.

推荐答案

您仍然选择了我想回答的答案,因为您希望它以 WordPress 的正确方式工作.请检查 wp_footer 是否在 body 标签关闭之前被调用.Action Hook wp_enqueue_scripts 将在 wp_footer 函数中调用.请尝试一次,让我知道结果.

Still you have selected the answer I would like to answer on your last desire that you want this to work in a proper way that WordPress do. Please check wp_footer is called before body tag closed or not. Action Hook wp_enqueue_scripts will called in wp_footer function. Please try once and let me know the result.

这篇关于在 WordPress 中导入 CSS 文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆