php - 如何在wordpress主题中包含styles.css?

标签 php wordpress wordpress-theming

我正在尝试将我的 style.css 样式表包含在我正在尝试开发的 wordpress 主题中(我的第一个)。问题:如何将其包含在内?我知道将以下代码放在我的 header.php 文件中是有效的:

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

但是我更愿意通过functions.php包含它,如下所示:
<?php
function firstTheme_style(){
    wp_enqueue_style( 'core', 'style.css', false ); 
}
add_action('wp_enqueue_scripts', 'firstTheme_style');
?>

然而,这根本不起作用(当我从 header.phps 'head' 中删除该行时,我的样式没有被看到?

最佳答案

以下方法包括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' );

关于php - 如何在wordpress主题中包含styles.css?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37391400/

相关文章:

css - 为什么我的 Wordpress 页面底部在 IE(而不是 Firefox)中被截断?

php - 如何使用php向mysql数据库插入多行,增加1行

用于检索按州分组的 WooCommerce 订单的 SQL 查询

html - 将 wordpress 网站标题与 Logo 对齐

php - 完整图像而不是缩略图

jquery - 使 fancybox 缩小图像而不是裁剪图像

html - 无法从容器中取出页脚

PHP - 多数据库连接突然不工作

php - 使用 select 获取变量

javascript - 如果我输入的 HTML id 是字符串 + php 变量,如何在 Jquery 中创建 Onclick 事件?