带有自定义字段的样式表中的PHP和CSS
我已经建立了一个PHP样式表,当我添加CSS时它就可以工作了带有自定义字段的样式表中的PHP和CSS,php,html,css,custom-fields,advanced-custom-fields,Php,Html,Css,Custom Fields,Advanced Custom Fields,我已经建立了一个PHP样式表,当我添加CSS时它就可以工作了 .test123 {color:red;} \\ this is working fine. 现在我想添加如下内容: .test123 {color:<?php [php code here that links to a custom field] ?>;} \\ this is my goal .test123{color:;}\\这是我的目标 我已经针对自定义字段测试了不同的PHP,如: .test123 {
.test123 {color:red;} \\ this is working fine.
现在我想添加如下内容:
.test123 {color:<?php [php code here that links to a custom field] ?>;} \\ this is my goal
.test123{color:;}\\这是我的目标
我已经针对自定义字段测试了不同的PHP,如:
.test123 { color: <?php the_field('color');?> ; } \\ linked to color picker of ACF
.test123{color:;}\\链接到ACF的颜色选择器
…但是CSS中的每个php代码都会返回以下消息:
“致命错误:调用未定义的函数”
我还不明白我做错了什么
这就是我现在设置的:
stylephp.php的工作版本
<?php
header('Content-Type: text/css');
$brandColor = "#990000";
$linkColor = "red";
?>
.test321 {
color: <?php echo $linkColor; ?>;
}
.test3210 {
color: <?php echo $brandColor; ?>;
}
<?php
add_action( 'wp_enqueue_scripts', 'theme_enqueue_styles' );
function theme_enqueue_styles() {
wp_enqueue_style( 'parent-style', get_template_directory_uri() . '/style.css' );
}
function add_stylesheet_to_head()
{
echo "<link href='http://[my test website address is normally here]/stylephp.php' rel='stylesheet' type='text/css'>";
}
add_action('wp_head', 'add_stylesheet_to_head');
?>
.test321{
颜色:;
}
.test3210{
颜色:;
}
functions.php的工作版本
<?php
header('Content-Type: text/css');
$brandColor = "#990000";
$linkColor = "red";
?>
.test321 {
color: <?php echo $linkColor; ?>;
}
.test3210 {
color: <?php echo $brandColor; ?>;
}
<?php
add_action( 'wp_enqueue_scripts', 'theme_enqueue_styles' );
function theme_enqueue_styles() {
wp_enqueue_style( 'parent-style', get_template_directory_uri() . '/style.css' );
}
function add_stylesheet_to_head()
{
echo "<link href='http://[my test website address is normally here]/stylephp.php' rel='stylesheet' type='text/css'>";
}
add_action('wp_head', 'add_stylesheet_to_head');
?>
读取错误说明一切调用未定义函数
。我没有看到你的代码中有一个名为_字段的函数。嗨,谢谢你的快速回复!我已经为Wordpress安装了ACF,所以我认为这个ACF函数是自动调用的。当你调用一个未定义的函数时,你会期望什么?不是一个有效的代码,至少。。。首先定义该函数,然后寻求帮助。