html - 如何基于 acf 设置简码样式

标签 html css wordpress shortcode

我想将我页面中 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/

相关文章:

html - 对旋转木马实现淡入淡出效果后控件消失

python - 如何将Python字典的某些键和值传递给HTML脚本

javascript - 替代多个“if 语句?

javascript - 将 .addEventListener 添加到函数中

wordpress - 在 Wordpress 中重写(翻译)URL 的分页部分

javascript - javascript中长时间跳跃的 Sprite ?

javascript - React 切换类 + CSS 转换,不起作用……为什么?

html - 下拉框在页面外渲染,当窗口宽度增加时不关闭

html - 如何将显示内联 block 移动到右侧?

php - 如何在没有 WP_Query 'title' 的情况下搜索帖子的 ,'content' &'meta_query' 's' ?