Skip to content

Commit

Permalink
Themes: Avoid double hashed value for background-color in custom ba…
Browse files Browse the repository at this point in the history
…ckgrounds.

This changeset replaces the hardcoded hash symbol with running `maybe_hash_hex_color()` on the full `background-color` value provided via the custom background feature, so the hash is only added if it is needed. By doing so, if a theme developer sets a background color value that uses a hash (#), WordPress won't add an additional hash anymore when outputting the relevant CSS. Duplicate hash symbols (##) can break CSS background color declarations.

Props hovhanneshovakimyan, joyously, poena, 
Fixes #40057.




git-svn-id: https://develop.svn.wordpress.org/trunk@59813 602fd350-edb4-49c9-b593-d223f7449a82
  • Loading branch information
audrasjb committed Feb 11, 2025
1 parent 8cc8eb5 commit 108af60
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/wp-admin/includes/class-custom-background.php
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ public function admin_page() {
$background_styles = '';
$bgcolor = get_background_color();
if ( $bgcolor ) {
$background_styles .= 'background-color: #' . $bgcolor . ';';
$background_styles .= 'background-color: ' . maybe_hash_hex_color( $bgcolor ) . ';';
}

$background_image_thumb = get_background_image();
Expand Down
2 changes: 1 addition & 1 deletion src/wp-includes/theme.php
Original file line number Diff line number Diff line change
Expand Up @@ -1893,7 +1893,7 @@ function _custom_background_cb() {
return;
}

$style = $color ? "background-color: #$color;" : '';
$style = $color ? 'background-color: ' . maybe_hash_hex_color( $color ) . ';' : '';

if ( $background ) {
$image = ' background-image: url("' . sanitize_url( $background ) . '");';
Expand Down

0 comments on commit 108af60

Please sign in to comment.