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().


Top ↑

Parameters

$color

(string)(Required)


Top ↑

Return

(string)


Top ↑

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;
}


Top ↑

Changelog

Changelog
VersionDescription
3.4.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.

Show More