admin管理员组文章数量:1122832
I have a customizer option that simply creates a dropdown populated with pages from the site. I need this dropdown to have the ability for multiple selections? Any ideas?
$wp_customize->add_control('options_my_dropdown',
array(
'label' => __('My Label'),
'description' => esc_html__('My Description'),
'section' => 'options_section',
'type' => 'dropdown-pages'
)
);
I have a customizer option that simply creates a dropdown populated with pages from the site. I need this dropdown to have the ability for multiple selections? Any ideas?
$wp_customize->add_control('options_my_dropdown',
array(
'label' => __('My Label'),
'description' => esc_html__('My Description'),
'section' => 'options_section',
'type' => 'dropdown-pages'
)
);
Share
Improve this question
edited May 16, 2024 at 13:32
cjbj
15k16 gold badges42 silver badges89 bronze badges
asked May 16, 2024 at 13:29
JonJon
3255 silver badges17 bronze badges
1 Answer
Reset to default 0Yes, this is possible, but you will have to really, really want it. It's difficult, because WordPress does not natively support the multiple
argument on select
inputs in the customizer. You can see this in de the render_content
function which outputs the html (just search the function for <select
). And even if you would succeed to add the argument, the customizer wouldn't know what to do with the selected items.
So, to get this done, you will have to extend the customizer. In terms of lines of code this is doable. WordPress itself contains multiple extensions to the customizer controls, for instance to add a color picker as an input type. Here's roughly what to do:
- Create a new file
WP_Customize_Control_Multiselect
- Check out the basic content in the color picker. You will need a line
public $type = 'multiselect';
, a simple constructor like the one in the color picker and a rendering function which you can adapt from thedropdown-pages
part ofWP_Customize_Control
. - Don't forget to include the file in your
functions.php
and call the control with$wp_customize->add_control (new Customize_Control_Multiselect ...
本文标签: phpWordPress Customizer addcontrol Dropdown of Pages with Multi Select
版权声明:本文标题:php - WordPress Customizer add_control Dropdown of Pages with Multi Select? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736306928a1933135.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论