-1

I am learning wordpress theme development. I want to change some styles in my theme option page. here is the css code

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

Theme option page

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

CSS file location : E:\xampp\htdocs\wordpress\wp-content\themes\theme-file\css\style.php Theme option file: E:\xampp\htdocs\wordpress\wp-content\themes\theme-file\functions.php

I also added this in my css php file

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

when I put those css style in header.php it works fine. But in css php file it is showing this

Fatal error: Call to undefined function esc_attr() in E:\xampp\htdocs\wordpress\wp-content\themes\theme-file\css\style.php on line 28

Faisal Ahmed
  • 91
  • 1
  • 1
  • 5

1 Answers1

3

Your file doesn't exist within the WordPress framework, and as such the WordPress functions like esc_attr and get_option are unavailable.

You can load in the WordPress framework like so at the top of your style.php file:

<?php

define('WP_USE_THEMES', false);
include('path/to/wp-load.php');
ceejayoz
  • 176,543
  • 40
  • 303
  • 368