首页 > 解决方案 > CSS 在 wordpress 网站中不起作用;在functions.php中调用未定义的函数get_template_uri()

问题描述

我正在尝试创办一家公司并为该公司创建网站。当我实时查看网站时,它全是 html,没有 css,但我在 ehder 和 index.php 的 rel 样式表中链接了它,但仍然没有 css!所以我在网上做了一些研究并创建了一个functions.php文件,认为这是问题所在。现在我收到此错误

警告:add_action() 缺少参数 2,在第 7 行的 /home2/elishaday/public_html/wp-content/themes/smmwca/css/functions.php 中调用并在 /home2/elishaday/public_html/wp-includes/plugin 中定义.php 在第 405 行

致命错误:在第 5 行的 /home2/elishaday/public_html/wp-content/themes/smmwca/functions.php 中调用未定义函数 get_template_uri()

这是我的functions.php 文件!

请帮忙

<?php
add_theme_support( 'post-thumbnails' );

function enqueue2_my_custom_styles(){
    wp_enqueue_style('animate css', get_template_uri() . '/css/styles.css', array(), '1.0.0', 'all');
}
add_action( 'wp_enqueue_scripts', 'enqueue2_my_custom_styles' );

标签: phphtmlcsswordpress

解决方案


警告显示您的 functions.php 位于另一个文件夹(css)中。functions.php 必须位于主题的根目录中。

另外,那get_template_directory_uri()不是get_template_uri()

<?php
add_theme_support( 'post-thumbnails' );

function enqueue2_my_custom_styles(){
    wp_enqueue_style('animate css', get_template_directory_uri() . '/css/styles.css', array(), '1.0.0', 'all');
}
add_action( 'wp_enqueue_scripts', 'enqueue2_my_custom_styles' );

推荐阅读