我想将我页面中 acf 字段的输出与我的短代码结合起来。文本应使用通过 acf 字段设置的颜色加下划线。
我尝试调用字段颜色并通过内联样式设置文本装饰。但这是行不通的。知道我做错了什么吗?
function quote_func($atts, $content = null){
$color = get_field('color');
$output = '<div>';
$output .= '<span style="text-decoration-color:' . echo the_field('color'); . '">' . $content . '</span>';
$output .= '</div>';
return $output;
}
add_shortcode( 'quote', 'quote_func' );
最佳答案
您应该回显您在函数开头设置的变量。
function quote_func($atts, $content = null){
$color = get_field('color');
$output = '<div>';
$output .= '<span style="text-decoration-color:' . $color . '">' . $content . '</span>';
$output .= '</div>';
return $output;
}
add_shortcode( 'quote', 'quote_func' );
关于html - 如何基于 acf 设置简码样式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57290380/