maybe_hash_hex_color() WordPress Function
maybe_hash_hex_color() is a Wordpress function that checks if a string is a valid hex color code, and if so, it converts it to a hash format. This function is useful for making sure that a string is a valid hex color code before using it in your Wordpress site.
maybe_hash_hex_color( string $color ) #
Ensures that any hex color is properly hashed.
Description
Otherwise, returns value untouched.
This method should only be necessary if using sanitize_hex_color_no_hash().
Parameters
- $color
(string)(Required)
Return
(string)
Source
File: wp-includes/formatting.php
function maybe_hash_hex_color( $color ) {
$unhashed = sanitize_hex_color_no_hash( $color );
if ( $unhashed ) {
return '#' . $unhashed;
}
return $color;
}
Expand full source codeCollapse full source codeView on TracView on GitHub
Changelog
| Version | Description |
|---|---|
| 3.4.0 | Introduced. |