在我的第一个插件中,用户可以从下拉列表中选择一个选项,这个选项会被保存在一个代码中,然后写入到页脚中。这是可行的,但问题是,我的默认选择(如HTML)被忽略了。
选材
>
>
密码
public function print_code(){
$location = get_option('location_select');
$url = 'https://' . esc_html($location) . '.domain.com/js/script.js';
wp_enqueue_script('myID', $url, array('jquery'), null, true);
}
public function additional_attrs($tag, $handle, $src){
if ($handle === 'myID'){
$tag = '';
}
return $tag;
}
如何在代码中将第一个选择作为默认选择?因为现在,如果用户不保存他的选择,输出代码中就不会写任何东西。
谢谢你的帮助!
发布于 2021-07-22 04:44:16
通过更新get_option
中的第二个值来解决
$location = get_option('location_select', 'ch');
参考资料:https://developer.wordpress.org/reference/functions/get_选项
https://wordpress.stackexchange.com/questions/392294
复制相似问题