Forked from ajskelton/WP Customizer - Dropdown-pages
Created
September 1, 2019 04:31
-
-
Save Asikur22/c9f0e3f2d99f26c3adc5d0c892fa5888 to your computer and use it in GitHub Desktop.
Add a Dropdown-pages field to the WordPress Customizer.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$wp_customize->add_setting( 'themeslug_dropdownpages_setting_id', array( | |
'capability' => 'edit_theme_options', | |
'sanitize_callback' => 'themeslug_sanitize_dropdown_pages', | |
) ); | |
$wp_customize->add_control( 'themeslug_dropdownpages_setting_id', array( | |
'type' => 'dropdown-pages', | |
'section' => 'custom_section', // Add a default or your own section | |
'label' => __( 'Custom Dropdown Pages' ), | |
'description' => __( 'This is a custom dropdown pages option.' ), | |
) ); | |
function themeslug_sanitize_dropdown_pages( $page_id, $setting ) { | |
// Ensure $input is an absolute integer. | |
$page_id = absint( $page_id ); | |
// If $page_id is an ID of a published page, return it; otherwise, return the default. | |
return ( 'publish' == get_post_status( $page_id ) ? $page_id : $setting->default ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment