• Resolved Andre

    (@andre-jutras)


    I’m working on a plugin to go with a theme.
    I’ve tried various options and searched the net with no luck.

    The theme has several options in the customizer, one is selecting (dropdown) a blog layout choice. However, I’ve been trying to code a plugin to add “more” blog layouts to the current array of 3 options.

    // Blog Layout
        $wp_customize->add_setting( 'tester_blog_layout', array(
    	'default' => 'classic',
    	'sanitize_callback' => 'tester_sanitize_select',
        ));
      
      $wp_customize->add_control( new Tester_Select_Control(	
    	$wp_customize,	'tester_blog_layout', array(
    	'label' => esc_html__( 'Blog Layout', 'tester' ),
    	'section' => 'tester_layout_settings',
    	'choices' => array(
    	  'classic' => esc_html__( 'Classic Right Sidebar', 'tester' ),
    	  'classic-left'  => esc_html__( 'Classic Left Sidebar', 'tester' ),
    	  'center' => esc_html__( 'Centered', 'tester' ),
    	)))
      );

    I cannot find any info on how this is done. Does anyone have a solution for this?

Viewing 2 replies - 1 through 2 (of 2 total)
  • Hi there!
    You can run $wp_customize->add_control from the plugin to re-add the theme control you wish to modify, but you may need to lower the priority of the plugin action so that it only runs after the theme action has run, because if the theme settings aren’t added yet you won’t be able to change them. Does that answer your question?

    Thread Starter Andre

    (@andre-jutras)

    Late reply..sorry, and thanks also!
    This is the added function…

    function tester_blog_layout2( $wp_customize ) {
    
      $wp_customize->add_control( new Tester_Select_Control(	
    	$wp_customize,	'tester_blog_layout2', array(
    		'label' => esc_html__( 'Blog Layout', 'empt' ),
    		'section' => 'tester_layout_settings',
    		'choices' => array(
    		'classic' => esc_html__( 'Classic Right Sidebar', 'empt' ),
    		'classic-left'  => esc_html__( 'Classic Left Sidebar', 'empt' ),
    		'center' => esc_html__( 'Centered', 'empt' ),
    		'grid' => esc_html__( 'Grid', 'empt' ),
    		)
    	)
    	)
      );
    }
    // Add function to the filter hook
    add_action( 'customize_register', 'tester_blog_layout2', 11);

    The previous layout control with the options in the customizer was removed and the new one replaces it–with the added “Grid” layout option showing in the dropdown choices.

    After numerous trials and errors, it appears to be working. I should also mention that I tested this out and wasn’t sure if the previous control with the options being replaced with the new version would change the previously selected layout for the blog–looks like it held it and was able to then select the new option(s).

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Add to existing customizer control via plugin’ is closed to new replies.