Created
April 16, 2013 03:51
-
-
Save noyb34/5393210 to your computer and use it in GitHub Desktop.
This snippet customize the colors of WP theme
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
<?php | |
// WORDPRESS 3.4 THEME OPTIONS | |
add_action( 'customize_register', 'hg_customize_register' ); | |
function hg_customize_register($wp_customize) | |
{ | |
$colors = array(); | |
$colors[] = array( 'slug'=>'content_bg_color', 'default' => '#ffffff', 'label' => __( 'Content Background Color', 'YOUR_THEME_NAME' ) ); | |
$colors[] = array( 'slug'=>'content_text_color', 'default' => '#000000', 'label' => __( 'Content Text Color', 'YOUR_THEME_NAME' ) ); | |
foreach($colors as $color) | |
{ | |
// SETTINGS | |
$wp_customize->add_setting( $color['slug'], array('default' => $color['default'], 'type' => 'option', 'capability' => 'edit_theme_options' )); | |
// CONTROLS | |
$wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, $color['slug'], array( 'label' => $color['label'], 'section' => 'colors', 'settings' => $color['slug'] ))); | |
} | |
} | |
function hex2rgb($hex) { | |
$hex = str_replace("#", "", $hex); | |
if(strlen($hex) == 3) { | |
$r = hexdec(substr($hex,0,1).substr($hex,0,1)); | |
$g = hexdec(substr($hex,1,1).substr($hex,1,1)); | |
$b = hexdec(substr($hex,2,1).substr($hex,2,1)); | |
} else { | |
$r = hexdec(substr($hex,0,2)); | |
$g = hexdec(substr($hex,2,2)); | |
$b = hexdec(substr($hex,4,2)); | |
} | |
$rgb = array($r, $g, $b); | |
//return implode(",", $rgb); // returns the rgb values separated by commas | |
return $rgb; // returns an array with the rgb values | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment