关于同一问题的新问题。 尝试使用带有自定义WordPress设置的php样式表。但是一旦我添加
$myoptions = get_option( 'option_name' );
进入此标头
<?php
header("Content-type: text/css; charset: UTF-8");
$myoptions = get_option( 'custom_ads' );
?>
样式表出错 500。
这是我在错误日志中遇到的错误
PHP 致命错误:未捕获错误:调用/nas/content/live/adsplugintest/wp-content/plugins/custom-ads-plugin/styles.php:11堆栈跟踪:#0 {main} 在第 11 行的/nas/content/live/adsplugintest/wp-content/plugins/custom-ads-plugin/styles.php 中调用未定义的函数 get_option(,引用者:domain.com/wp-includes/options.php/
您需要包含WordOress的其余部分,以便函数get_option
可用于您的动态样式表。
即使它是由WordPress模板调用的,它也被服务器视为自己的隔离请求,并且必须这样进行评估。(这意味着其中使用的所有函数都必须包含在行的某个地方。
<?php
// wp-content/plugins/custom-ads-plugin/styles.php
require ('../../../wp-blog-header.php');
header("Content-type: text/css; charset: UTF-8");
$myoptions = get_option( 'custom_ads' );