wc_format_hex( string $hex )

Format string as hex.


Description Description


Parameters Parameters

$hex

(Required) HEX color.


Top ↑

Return Return

(string|null)


Top ↑

Source Source

File: includes/wc-formatting-functions.php

	function wc_format_hex( $hex ) {
		$hex = trim( str_replace( '#', '', $hex ) );

		if ( strlen( $hex ) === 3 ) {
			$hex = $hex[0] . $hex[0] . $hex[1] . $hex[1] . $hex[2] . $hex[2];
		}

		return $hex ? '#' . $hex : null;
	}


Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.