sanitize_hex_color_no_hash( string $color )

Sanitizes a hex color without a hash. Use sanitize_hex_color() when possible.


Description Description

Saving hex colors without a hash puts the burden of adding the hash on the UI, which makes it difficult to use or upgrade to other color types such as rgba, hsl, rgb, and html color names.

Returns either ”, a 3 or 6 digit hex color (without a #), or null.


Parameters Parameters

$color

(string) (Required)


Top ↑

Return Return

(string|null)


Top ↑

Source Source

File: wp-includes/formatting.php

function sanitize_hex_color_no_hash( $color ) {
	$color = ltrim( $color, '#' );

	if ( '' === $color ) {
		return '';
	}

	return sanitize_hex_color( '#' . $color ) ? $color : null;
}

Top ↑

Changelog Changelog

Changelog
Version Description
3.4.0 Introduced.


Top ↑

User Contributed Notes User Contributed Notes

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