我有一系列自定义元框,按照下面的代码配置。一切都很好,但当用户没有输入值时,框中的默认值是"。这当然是一个问题,因为它在前端打印出来。如果默认值为空,则前端不会输出任何内容。
有什么想法吗?
$video_url_1 = isset( $values['cf_private_meta_box_video_url_1'] ) ? esc_attr( $values['cf_private_meta_box_video_url_1'][0] ) : ”;
$video_caption_1 = isset( $values['cf_private_meta_box_video_caption_1'] ) ? esc_attr( $values['cf_private_meta_box_video_caption_1'][0] ) : ”;
<label for="cf_private_meta_box_video_url">Video URL 1</label>
<input type="text" class="widefat" name="cf_private_meta_box_video_url_1" id="cf_private_meta_box_video_url_1" value="<?php echo $video_url_1; ?>" />
<label for="cf_private_meta_box_video_caption">Video Caption 1</label>
<input type="text" class="widefat" name="cf_private_meta_box_video_caption_1" id="cf_private_meta_box_video_caption_1" value="<?php echo $video_caption_1; ?>" />
您使用的字符”
不是有效的PHP语法。PHP将其作为文字字符”
进行插值。将其更改为两个单引号、两个双引号或null。即;
isset(...) ? esc_attr(...) : '';
或
isset(...) ? esc_attr(...) : "";
或
isset(...) ? esc_attr(...) : null;
这三个都是有效的PHP语法