Make WordPress Core

Changeset 59813


Ignore:
Timestamp:
02/11/2025 09:05:00 PM (2 months ago)
Author:
audrasjb
Message:

Themes: Avoid double hashed value for background-color in custom backgrounds.

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.

Location:
trunk/src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/includes/class-custom-background.php

    r59554 r59813  
    289289            $bgcolor           = get_background_color();
    290290            if ( $bgcolor ) {
    291                 $background_styles .= 'background-color: #' . $bgcolor . ';';
     291                $background_styles .= 'background-color: ' . maybe_hash_hex_color( $bgcolor ) . ';';
    292292            }
    293293
  • trunk/src/wp-includes/theme.php

    r58975 r59813  
    18941894    }
    18951895
    1896     $style = $color ? "background-color: #$color;" : '';
     1896    $style = $color ? 'background-color: ' . maybe_hash_hex_color( $color ) . ';' : '';
    18971897
    18981898    if ( $background ) {
Note: See TracChangeset for help on using the changeset viewer.