-1

I'm new to WordPress I want to add simple color picker in theme options.I tried but not getting can anyone suggest me?

0

Working code to set color customizer in wordpress theme settings:

  function color_customizer($wp_customize){
  $wp_customize->add_section( 'theme_colors_settings', array(
      'title' => __( 'Theme Colors Settings', 'themeslug' ),
      'priority' => 5,
    ) );

    $theme_colors = array();

    // Navigation Background Color
    $theme_colors[] = array(
      'slug'=>'color_section_name',
      'default' => '#000000',
      'label' => __('Color Section Title', 'themeslug')
    );

    foreach( $theme_colors as $color ) {

      $wp_customize->add_setting(
        $color['slug'], array(
          'default' => $color['default'],
          'sanitize_callback' => 'sanitize_hex_color',
          'type' => 'option',
          'capability' => 'edit_theme_options'
        )
      );

      $wp_customize->add_control(
        new WP_Customize_Color_Control(
          $wp_customize,
          $color['slug'],
          array('label' => $color['label'],
          'section' => 'theme_colors_settings',
          'settings' => $color['slug'])
        )
      );
    }
  }

  add_action( 'customize_register', 'color_customizer' );
  • how to call in php. – Mehraj Khan Apr 16 '18 at 12:36
  • Add this code in your themes functions.php file and use get_theme_mod('color_section_name') to get value – Bhupen Apr 16 '18 at 13:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.