Make WordPress Core


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

    r59907 r60483  
    3636            <div class="site-header-main">
    3737                <div class="site-branding">
    38                     <?php twentysixteen_the_custom_logo(); ?>
    39                     <?php $is_front = ! is_paged() && ( is_front_page() || ( is_home() && ( (int) get_option( 'page_for_posts' ) !== get_queried_object_id() ) ) ); ?>
    40                     <?php if ( is_front_page() && is_home() ) : ?>
    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                     <?php else : ?>
    43                         <p class="site-title"><a href="<?php echo esc_url( home_url( '/' ) ); ?>" rel="home" <?php echo $is_front ? 'aria-current="page"' : ''; ?>><?php bloginfo( 'name' ); ?></a></p>
     38                    <?php
     39                    twentysixteen_the_custom_logo();
     40                    $is_front  = ! is_paged() && ( is_front_page() || ( is_home() && ( (int) get_option( 'page_for_posts' ) !== get_queried_object_id() ) ) );
     41                    $site_name = get_bloginfo( 'name', 'display' );
     42
     43                    if ( $site_name && is_front_page() && is_home() ) :
     44                        ?>
     45                        <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>
     46                    <?php elseif ( $site_name ) : ?>
     47                        <p 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></p>
    4448                        <?php
    4549                    endif;
Note: See TracChangeset for help on using the changeset viewer.