Skip to content

Commit d71b1d8

Browse files
committed
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. git-svn-id: https://develop.svn.wordpress.org/trunk@60483 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 74c101b commit d71b1d8

File tree

9 files changed

+112
-49
lines changed

9 files changed

+112
-49
lines changed

src/wp-content/themes/twentyeleven/header.php

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,14 +78,26 @@
7878
<div id="page" class="hfeed">
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.
91103
if ( function_exists( 'get_custom_header' ) ) {

src/wp-content/themes/twentyfifteen/header.php

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -32,23 +32,24 @@
3232
<header id="masthead" class="site-header">
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 -->
5455
</header><!-- .site-header -->

src/wp-content/themes/twentyfourteen/header.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,12 @@
5050

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">
5661
<a href="#search-container" class="screen-reader-text" aria-expanded="false" aria-controls="search-container">

src/wp-content/themes/twentyseventeen/template-parts/header/site-branding.php

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,18 @@
1515
<?php the_custom_logo(); ?>
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; ?>
24-
2518
<?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' );
21+
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

2832
if ( $description || is_customize_preview() ) :

src/wp-content/themes/twentysixteen/header.php

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,16 @@
3535
<header id="masthead" class="site-header">
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;
4650

src/wp-content/themes/twentyten/header.php

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -68,17 +68,29 @@
6868
<div id="header">
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>
79-
8071
<?php
81-
// Compatibility with versions of WordPress prior to 3.4.
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' );
76+
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
/*
8496
* We need to figure out what the minimum width should be for our featured image.

src/wp-content/themes/twentythirteen/header.php

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,19 @@
2929
?>
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

3847
<div id="navbar" class="navbar">

src/wp-content/themes/twentytwelve/header.php

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,21 @@
3737
<a class="screen-reader-text skip-link" href="#content"><?php _e( 'Skip to content', 'twentytwelve' ); ?></a>
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

4557
<nav id="site-navigation" class="main-navigation">

src/wp-content/themes/twentytwenty/inc/template-tags.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,10 @@ function twentytwenty_site_logo( $args = array(), $display = true ) {
6363
$contents = sprintf( $args['logo'], $logo, esc_html( $site_title ) );
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 (
6872
( is_front_page() || is_home() && ( (int) get_option( 'page_for_posts' ) !== get_queried_object_id() ) )

0 commit comments

Comments
 (0)