twentyfifteen_hex2rgb

Convert HEX to RGB.

Description

(array) twentyfifteen_hex2rgb( (string) $color ); 

Returns (array)

Array containing RGB (red, green, and blue) values for the given HEX code, empty array otherwise.

Parameters (1)

0. $color (string)
The original color, in 3- or 6-digit hexadecimal form.

Usage

  1. if ( !function_exists( 'twentyfifteen_hex2rgb' ) ) { 
  2. require_once '/inc/custom-header.php'; 
  3.  
  4. // The original color, in 3- or 6-digit hexadecimal form. 
  5. $color = ''; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = twentyfifteen_hex2rgb($color); 
  9.  

Defined (1)

The function is defined in the following location(s).

/inc/custom-header.php  
  1. function twentyfifteen_hex2rgb( $color ) { 
  2. $color = trim( $color, '#' ); 
  3.  
  4. if ( strlen( $color ) == 3 ) { 
  5. $r = hexdec( substr( $color, 0, 1 ).substr( $color, 0, 1 ) ); 
  6. $g = hexdec( substr( $color, 1, 1 ).substr( $color, 1, 1 ) ); 
  7. $b = hexdec( substr( $color, 2, 1 ).substr( $color, 2, 1 ) ); 
  8. } else if ( strlen( $color ) == 6 ) { 
  9. $r = hexdec( substr( $color, 0, 2 ) ); 
  10. $g = hexdec( substr( $color, 2, 2 ) ); 
  11. $b = hexdec( substr( $color, 4, 2 ) ); 
  12. } else { 
  13. return array(); 
  14.  
  15. return array( 'red' => $r, 'green' => $g, 'blue' => $b );