Make WordPress Core

Changeset 60483


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.

Location:
trunk/src/wp-content/themes
Files:
9 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.
  • trunk/src/wp-content/themes/twentyfifteen/header.php

    r59907 r60483  
    3333            <div class="site-branding">
    3434                <?php
    35                     twentyfifteen_the_custom_logo();
    36                     $is_front = ! is_paged() && ( is_front_page() || ( is_home() && ( (int) get_option( 'page_for_posts' ) !== get_queried_object_id() ) ) );
    37                 if ( is_front_page() && is_home() ) :
     35                twentyfifteen_the_custom_logo();
     36                $is_front  = ! is_paged() && ( is_front_page() || ( is_home() && ( (int) get_option( 'page_for_posts' ) !== get_queried_object_id() ) ) );
     37                $site_name = get_bloginfo( 'name', 'display' );
     38
     39                if ( $site_name && is_front_page() && is_home() ) :
    3840                    ?>
    39                         <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>
    40                     <?php else : ?>
    41                         <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>
    42                         <?php
    43                     endif;
     41                    <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>
     42                <?php elseif ( $site_name ) : ?>
     43                    <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>
     44                    <?php
     45                endif;
    4446
    45                     $description = get_bloginfo( 'description', 'display' );
    46                     if ( $description || is_customize_preview() ) :
    47                         ?>
    48                         <p class="site-description"><?php echo $description; ?></p>
    49                         <?php
    50                     endif;
     47                $description = get_bloginfo( 'description', 'display' );
     48                if ( $description || is_customize_preview() ) :
    5149                    ?>
     50                    <p class="site-description"><?php echo $description; ?></p>
     51                <?php endif; ?>
     52
    5253                <button class="secondary-toggle"><?php _e( 'Menu and widgets', 'twentyfifteen' ); ?></button>
    5354            </div><!-- .site-branding -->
  • trunk/src/wp-content/themes/twentyfourteen/header.php

    r59991 r60483  
    5151    <header id="masthead" class="site-header">
    5252        <div class="header-main">
    53             <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>
     53            <?php
     54            $site_name = get_bloginfo( 'name', 'display' );
     55            if ( $site_name ) :
     56                ?>
     57                <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>
     58            <?php endif; ?>
    5459
    5560            <div class="search-toggle">
  • trunk/src/wp-content/themes/twentyseventeen/template-parts/header/site-branding.php

    r59907 r60483  
    1616
    1717        <div class="site-branding-text">
    18             <?php $is_front = ! is_paged() && ( is_front_page() || ( is_home() && ( (int) get_option( 'page_for_posts' ) !== get_queried_object_id() ) ) ); ?>
    19             <?php if ( is_front_page() ) : ?>
    20                 <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>
    21             <?php else : ?>
    22                 <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>
    23             <?php endif; ?>
     18            <?php
     19            $is_front  = ! is_paged() && ( is_front_page() || ( is_home() && ( (int) get_option( 'page_for_posts' ) !== get_queried_object_id() ) ) );
     20            $site_name = get_bloginfo( 'name', 'display' );
    2421
    25             <?php
     22            if ( $site_name && is_front_page() ) :
     23                ?>
     24                <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>
     25            <?php elseif ( $site_name ) : ?>
     26                <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>
     27                <?php
     28            endif;
     29
    2630            $description = get_bloginfo( 'description', 'display' );
    2731
  • 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;
  • trunk/src/wp-content/themes/twentyten/header.php

    r60159 r60483  
    6969        <div id="masthead">
    7070            <div id="branding" role="banner">
    71                 <?php $heading_tag = ( is_home() || is_front_page() ) ? 'h1' : 'div'; ?>
    72                 <<?php echo $heading_tag; ?> id="site-title">
    73                     <span>
    74                     <?php $is_front = ! is_paged() && ( is_front_page() || ( is_home() && ( (int) get_option( 'page_for_posts' ) !== get_queried_object_id() ) ) ); ?>
    75                         <a href="<?php echo esc_url( home_url( '/' ) ); ?>" rel="home" <?php echo $is_front ? 'aria-current="page"' : ''; ?>><?php bloginfo( 'name' ); ?></a>
    76                     </span>
    77                 </<?php echo $heading_tag; ?>>
    78                 <div id="site-description"><?php bloginfo( 'description' ); ?></div>
     71                <?php
     72                $heading_tag      = ( is_home() || is_front_page() ) ? 'h1' : 'div';
     73                $is_front         = ! is_paged() && ( is_front_page() || ( is_home() && ( (int) get_option( 'page_for_posts' ) !== get_queried_object_id() ) ) );
     74                $site_name        = get_bloginfo( 'name', 'display' );
     75                $site_description = get_bloginfo( 'description', 'display' );
    7976
    80                 <?php
    81                     // Compatibility with versions of WordPress prior to 3.4.
     77                if ( $site_name ) :
     78                    ?>
     79                    <<?php echo $heading_tag; ?> id="site-title">
     80                        <span>
     81                            <a href="<?php echo esc_url( home_url( '/' ) ); ?>" rel="home" <?php echo $is_front ? 'aria-current="page"' : ''; ?>><?php echo $site_name; ?></a>
     82                        </span>
     83                    </<?php echo $heading_tag; ?>>
     84                    <?php
     85                endif;
     86
     87                if ( $site_description ) :
     88                    ?>
     89                    <div id="site-description"><?php echo $site_description; ?></div>
     90                    <?php
     91                endif;
     92
     93                // Compatibility with versions of WordPress prior to 3.4.
    8294                if ( function_exists( 'get_custom_header' ) ) {
    8395                    /*
  • trunk/src/wp-content/themes/twentythirteen/header.php

    r59913 r60483  
    3030        </a>
    3131        <header id="masthead" class="site-header">
    32         <?php $is_front = ! is_paged() && ( is_front_page() || ( is_home() && ( (int) get_option( 'page_for_posts' ) !== get_queried_object_id() ) ) ); ?>
     32            <?php
     33            $is_front         = ! is_paged() && ( is_front_page() || ( is_home() && ( (int) get_option( 'page_for_posts' ) !== get_queried_object_id() ) ) );
     34            $site_name        = get_bloginfo( 'name', 'display' );
     35            $site_description = get_bloginfo( 'description', 'display' );
     36
     37            ?>
    3338            <a class="home-link" href="<?php echo esc_url( home_url( '/' ) ); ?>" rel="home" <?php echo $is_front ? 'aria-current="page"' : ''; ?>>
    34                 <h1 class="site-title"><?php bloginfo( 'name' ); ?></h1>
    35                 <h2 class="site-description"><?php bloginfo( 'description' ); ?></h2>
     39                <?php if ( $site_name ) : ?>
     40                    <h1 class="site-title"><?php echo $site_name; ?></h1>
     41                <?php endif; ?>
     42                <?php if ( $site_description ) : ?>
     43                    <h2 class="site-description"><?php echo $site_description; ?></h2>
     44                <?php endif; ?>
    3645            </a>
    3746
  • 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
  • trunk/src/wp-content/themes/twentytwenty/inc/template-tags.php

    r59907 r60483  
    6464        $classname = $args['logo_class'];
    6565    } else {
     66        if ( ! $site_title ) {
     67            return '';
     68        }
     69
    6670        $contents = sprintf( $args['title'], esc_url( get_home_url( null, '/' ) ), esc_html( $site_title ) );
    6771        if (
Note: See TracChangeset for help on using the changeset viewer.