我正在使用WordPress ACF plugin 和这个函数填充 WordPress HTML表:(我认为它是 general PHP question )
add_shortcode('custom_acf',custom_acf_callback);
function custom_acf_callback ($atts = '')
{
$value = shortcode_atts( array(
'my_field' => '',
), $atts );
//the main part starts from here:
if ($custom_acf_value){
return $custom_acf_value;
}
else {
//and the problem is here:
return '';
}
我使用这个棘手的CSS代码隐藏空表单元格:
td:empty {
display: none;
}
Problem 是空单元格不会被隐藏,因为表格单元格的默认值是我的短代码,我尝试使用:
return NULL;
并且还简单地使用"return",但它们不会在表格单元格中返回空 . 请注意 css 是单独测试的并且没有问题,如何返回真正的 empty 值?
2 回答
我想你需要在使用方法
add_shortcode
之前检查返回值: