首页 > 解决方案 > 如何根据 acf 设置简码样式

问题描述

我想将我页面中的 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' );

标签: htmlcsswordpressshortcode

解决方案


您应该回显您在函数开头设置的变量。

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' );

推荐阅读