【问题标题】:PHP in CSS File Wordpress [duplicate]CSS文件Wordpress中的PHP [重复]
【发布时间】:2014-10-20 20:17:10
【问题描述】:

我正在学习 wordpress 主题开发。我想在我的主题选项页面中更改一些样式。这是css代码

background: #<?php echo esc_attr( get_option('header_bg') ); ?>;

主题选项页面

register_setting('theme-setting-group','header_bg');

CSS 文件位置:E:\xampp\htdocs\wordpress\wp-content\themes\theme-file\css\style.php 主题选项文件:E:\xampp\htdocs\wordpress\wp-content\themes\theme-file\functions.php

我还在我的 css php 文件中添加了这个

<?php header("Content-type: text/css", true);?>

当我将这些 css 样式放入 header.php 时,它工作正常。但是在 css php 文件中它显示了这个

致命错误:在 E:\xampp\htdocs\wordpress\wp-content\themes\theme-file\css\style.php 中调用未定义函数 esc_attr() b> 在第 28 行

【问题讨论】:

    标签: php css wordpress wordpress-theming fatal-error


    【解决方案1】:

    您的文件在 WordPress 框架中不存在,因此像 esc_attrget_option 这样的 WordPress 函数不可用。

    您可以像这样在 style.php 文件的顶部加载 WordPress 框架:

    <?php
    
    define('WP_USE_THEMES', false);
    include('path/to/wp-load.php');
    

    【讨论】:

    • @FaisalAhmed 我不知道,它有效吗?我说要包括wp-load.php
    猜你喜欢
    • 2021-11-28
    • 2012-12-26
    • 2014-03-08
    • 1970-01-01
    • 2012-11-02
    • 2011-03-12
    • 2014-09-07
    • 1970-01-01
    • 2012-10-23
    相关资源
    最近更新 更多