• I am trying to use a dropdown page control to select a page but it is not working. With others control it works perfect.

    functions.php

    //section
    $wp_customize->add_section('themename_color_scheme', array(
        'title'    => __('Color Scheme', 'themename'),
        'description' => '',
        'priority' => 120,
    ));
    //setting
    $wp_customize->add_setting('landing1', array(
            'capability'     => 'edit_theme_options',
            'type'           => 'option',
    
        ));
    //control
    $wp_customize->add_control('ld', array(
            'label'      => 'Front page section 1',
            'section'    => 'themename_color_scheme',
            'type'    => 'dropdown-pages',
            'settings'   => 'landing1',
    ));

    page:

    //trying to show the data (not working :/  )
    $mod = get_theme_mod( 'ld');
    echo($mod);
    echo var_dump($mod);

    echo ($mod) dont show anything and var_dump show “boolean false”

Viewing 4 replies - 1 through 4 (of 4 total)
  • Thread Starter tiago fabre

    (@tiagofabre)

    Here’s what’s working for me –

    $wp_customize->add_section(
    		'smu_bio', array(
    			'title' => __('Bio Section', 'smu'),
    			'priority' => 70,
    		));
    
    	// Link
    
    	$wp_customize->add_setting('smu_bio_link', array(
    		// note - works with or without capability & type set
    		'capability' => 'edit_theme_options',
    		'type' => 'option',
    		// note - need to add sanitize callback
    	));
    
    	$wp_customize->add_control('smu_bio_link', array(
    		'label' => __('Link', 'smu'),
    		'section' => 'smu_bio',
    		'type' => 'dropdown-pages',
    		'settings' => 'smu_bio_link',
    	)); // end link

    I was fine up to this point, but my issue was that using echo get_theme_mod('smu_bio_link'); was returning the page ID, when I needed the permalink.

    The solution, in my case, was so simple and obvious that it took me about three hours before someone pointed out –

    <?php echo get_permalink(get_theme_mod('smu_bio_link')); ?>

    Thanks to Brady Vercher ( @bradyvercher ) for helping me out with it.

    Hope this helps in some way.

    Hi Tiago –

    This is probably a bit late but anyway:
    In your page template you are trying to retrieve the wrong part from your customizer code:

    $mod = get_theme_mod( 'ld');
    echo($mod);
    echo var_dump($mod);

    this is trying to retrieve information from the setting ‘ld’ – which in your customizer code you have named the controller ‘ld’. Your Controller is calling the setting ‘landing1’. Controllers only handle the changing of your settings (in this instance)

    try:

    $mod = get_theme_mod( 'landing1');
    echo($mod);
    echo var_dump($mod);

    Thread Starter tiago fabre

    (@tiagofabre)

    Thank you guys!

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘wp customizer api dropdown-pages’ is closed to new replies.