Make WordPress Core


Ignore:
Timestamp:
07/18/2025 03:29:06 AM (7 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/twentytwelve/header.php

    r59912 r60483  
    3838    <header id="masthead" class="site-header">
    3939        <hgroup>
    40         <?php $is_front = ! is_paged() && ( is_front_page() || ( is_home() && ( (int) get_option( 'page_for_posts' ) !== get_queried_object_id() ) ) ); ?>
    41             <h1 class="site-title"><a href="<?php echo esc_url( home_url( '/' ) ); ?>" rel="home" <?php echo $is_front ? 'aria-current="page"' : ''; ?>><?php bloginfo( 'name' ); ?></a></h1>
    42             <h2 class="site-description"><?php bloginfo( 'description' ); ?></h2>
     40            <?php
     41            $is_front         = ! is_paged() && ( is_front_page() || ( is_home() && ( (int) get_option( 'page_for_posts' ) !== get_queried_object_id() ) ) );
     42            $site_name        = get_bloginfo( 'name', 'display' );
     43            $site_description = get_bloginfo( 'description', 'display' );
     44
     45            if ( $site_name ) :
     46                ?>
     47                <h1 class="site-title"><a href="<?php echo esc_url( home_url( '/' ) ); ?>" rel="home" <?php echo $is_front ? 'aria-current="page"' : ''; ?>><?php echo $site_name; ?></a></h1>
     48                <?php
     49            endif;
     50
     51            if ( $site_description ) :
     52                ?>
     53                <h2 class="site-description"><?php echo $site_description; ?></h2>
     54            <?php endif; ?>
    4355        </hgroup>
    4456
Note: See TracChangeset for help on using the changeset viewer.