We build easy to manage, secure and Mobile friendly Websites.

How To Add a Dropdown Pages Field to the WordPress Customizer


In this tutorial, I will be showing you how to add a dropdown page field to WordPress customizer.

I have discussed about the parameters for add_setting() and add_control() functions in my previous tutorial.

Create setting for dropdown page field

$wp_customize->add_setting('themeslug_dropdownpage_id', array(
    'default'        => '',
    ));

Create control for dropdown page field


$wp_customize->add_control('themeslug_dropdownpage_id', array(
  'label' => esc_html__('Input Type Dropdown Page:', 'themeslug'),
    'type' => 'dropdown-pages',
    'priority' => 6,
    'section'    => 'themeslug_section_id',
    'setting'   => 'themeslug_dropdownpage_id',
    'capability' => 'edit_theme_options',
    ));	

Usage

Add the code below to your page to display the output.

/* Output Page ID*/
<?php echo get_theme_mod( 'themeslug_dropdownpage_id'); ?>  
/*output Page url*/
<?php echo get_permalink(get_theme_mod( 'themeslug_dropdownpage_id', '' ));?>

Leave a Reply

Your email address will not be published.