Make WordPress Core


Ignore:
Timestamp:
07/18/2025 03:29:06 AM (6 months ago)
Author:
joedolson
Message:

Bundled Theme: Prevent output of empty title tags.

In Twenty Ten, Twenty Eleven, Twenty Twelve, Twenty Thirteen, Twenty Fourteen, Twenty Fifteen, Twenty Sixteen, Twenty Seventeen, and Twenty Twenty, an empty site title would result in an empty heading and/or an empty link in the site header. These can pollute the heading hierarchy and add a un-named link in screen reader navigation.

Prevent the output of wrapping tags if site title or site description have no value.

Props tsquez, audrasjb, sabernhardt, rehanali, sukhendu2002, dilipbheda, sirlouen, joedolson.
Fixes #44656.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-content/themes/twentyeleven/header.php

    r60159 r60483  
    7979    <header id="branding">
    8080            <hgroup>
    81             <?php $is_front = ! is_paged() && ( is_front_page() || ( is_home() && ( (int) get_option( 'page_for_posts' ) !== get_queried_object_id() ) ) ); ?>
    82                 <h1 id="site-title"><span><a href="<?php echo esc_url( home_url( '/' ) ); ?>" rel="home" <?php echo $is_front ? 'aria-current="page"' : ''; ?>><?php bloginfo( 'name' ); ?></a></span></h1>
    83                 <h2 id="site-description"><?php bloginfo( 'description' ); ?></h2>
     81                <?php
     82                $is_front         = ! is_paged() && ( is_front_page() || ( is_home() && ( (int) get_option( 'page_for_posts' ) !== get_queried_object_id() ) ) );
     83                $site_name        = get_bloginfo( 'name', 'display' );
     84                $site_description = get_bloginfo( 'description', 'display' );
     85
     86                if ( $site_name ) :
     87                    ?>
     88                    <h1 id="site-title"><span><a href="<?php echo esc_url( home_url( '/' ) ); ?>" rel="home" <?php echo $is_front ? 'aria-current="page"' : ''; ?>><?php echo $site_name; ?></a></span></h1>
     89                    <?php
     90                endif;
     91
     92                if ( $site_description ) :
     93                    ?>
     94                    <h2 id="site-description"><?php echo $site_description; ?></h2>
     95                <?php endif; ?>
    8496            </hgroup>
    8597
    8698            <?php
    87                 // Check to see if the header image has been removed.
    88                 $header_image = get_header_image();
     99            // Check to see if the header image has been removed.
     100            $header_image = get_header_image();
    89101            if ( $header_image ) :
    90102                // Compatibility with versions of WordPress prior to 3.4.
Note: See TracChangeset for help on using the changeset viewer.