Skip to content

Commit b218bbe

Browse files
committed
Fix empty markup when site title or description is empty
1 parent a8b0726 commit b218bbe

9 files changed

Lines changed: 79 additions & 28 deletions

File tree

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,17 @@
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() ) ) ); ?>
81+
<?php
82+
$is_front = ! is_paged() && ( is_front_page() || ( is_home() && ( (int) get_option( 'page_for_posts' ) !== get_queried_object_id() ) ) );
83+
?>
84+
85+
<?php if ( ! empty( get_bloginfo( 'name' ) ) ) : ?>
8286
<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>
87+
<?php endif; ?>
88+
89+
<?php if ( ! empty( get_bloginfo( 'description' ) ) ) : ?>
8390
<h2 id="site-description"><?php bloginfo( 'description' ); ?></h2>
91+
<?php endif; ?>
8492
</hgroup>
8593

8694
<?php

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

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -32,23 +32,26 @@
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() ) :
38-
?>
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;
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() ) ) );
4437

45-
$description = get_bloginfo( 'description', 'display' );
46-
if ( $description || is_customize_preview() ) :
38+
if ( ! empty( get_bloginfo( 'name' ) ) ) :
39+
if ( is_front_page() && is_home() ) :
4740
?>
48-
<p class="site-description"><?php echo $description; ?></p>
49-
<?php
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>
44+
<?php
5045
endif;
46+
endif;
47+
48+
$description = get_bloginfo( 'description', 'display' );
49+
if ( $description || is_customize_preview() ) :
5150
?>
51+
<p class="site-description"><?php echo $description; ?></p>
52+
<?php
53+
endif;
54+
?>
5255
<button class="secondary-toggle"><?php _e( 'Menu and widgets', 'twentyfifteen' ); ?></button>
5356
</div><!-- .site-branding -->
5457
</header><!-- .site-header -->

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,9 @@
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 if ( ! empty( get_bloginfo( 'name' ) ) ) : ?>
54+
<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>
55+
<?php endif; ?>
5456

5557
<div class="search-toggle">
5658
<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: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,19 @@
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+
21+
if ( ! empty( get_bloginfo( 'name' ) ) ) :
22+
if ( 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 bloginfo( 'name' ); ?></a></h1>
25+
<?php else : ?>
26+
<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>
27+
<?php
28+
endif;
29+
endif;
30+
2631
$description = get_bloginfo( 'description', 'display' );
2732

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

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

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,17 @@
3636
<div class="site-header-main">
3737
<div class="site-branding">
3838
<?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() ) : ?>
39+
<?php
40+
$is_front = ! is_paged() && ( is_front_page() || ( is_home() && ( (int) get_option( 'page_for_posts' ) !== get_queried_object_id() ) ) );
41+
42+
if ( ! empty( get_bloginfo( 'name' ) ) ) :
43+
if ( is_front_page() && is_home() ) :
44+
?>
4145
<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>
4246
<?php else : ?>
4347
<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>
44-
<?php
48+
<?php
49+
endif;
4550
endif;
4651

4752
$description = get_bloginfo( 'description', 'display' );

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

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,14 +68,22 @@
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'; ?>
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+
?>
75+
76+
<?php if ( ! empty( get_bloginfo( 'name' ) ) ) : ?>
7277
<<?php echo $heading_tag; ?> id="site-title">
7378
<span>
74-
<?php $is_front = ! is_paged() && ( is_front_page() || ( is_home() && ( (int) get_option( 'page_for_posts' ) !== get_queried_object_id() ) ) ); ?>
7579
<a href="<?php echo esc_url( home_url( '/' ) ); ?>" rel="home" <?php echo $is_front ? 'aria-current="page"' : ''; ?>><?php bloginfo( 'name' ); ?></a>
7680
</span>
7781
</<?php echo $heading_tag; ?>>
82+
<?php endif; ?>
83+
84+
<?php if ( ! empty( get_bloginfo( 'description' ) ) ) : ?>
7885
<div id="site-description"><?php bloginfo( 'description' ); ?></div>
86+
<?php endif; ?>
7987

8088
<?php
8189
// Compatibility with versions of WordPress prior to 3.4.

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,20 @@
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+
35+
if ( ! empty( get_bloginfo( 'name' ) ) || ! empty( get_bloginfo( 'description' ) ) ) :
36+
?>
3337
<a class="home-link" href="<?php echo esc_url( home_url( '/' ) ); ?>" rel="home" <?php echo $is_front ? 'aria-current="page"' : ''; ?>>
38+
<?php if ( ! empty( get_bloginfo( 'name' ) ) ) : ?>
3439
<h1 class="site-title"><?php bloginfo( 'name' ); ?></h1>
40+
<?php endif; ?>
41+
<?php if ( ! empty( get_bloginfo( 'description' ) ) ) : ?>
3542
<h2 class="site-description"><?php bloginfo( 'description' ); ?></h2>
43+
<?php endif; ?>
3644
</a>
45+
<?php endif; ?>
3746

3847
<div id="navbar" class="navbar">
3948
<nav id="site-navigation" class="navigation main-navigation">

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,14 @@
3838
<header id="masthead" class="site-header">
3939
<hgroup>
4040
<?php $is_front = ! is_paged() && ( is_front_page() || ( is_home() && ( (int) get_option( 'page_for_posts' ) !== get_queried_object_id() ) ) ); ?>
41+
42+
<?php if ( ! empty( get_bloginfo( 'name' ) ) ) : ?>
4143
<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>
44+
<?php endif; ?>
45+
46+
<?php if ( ! empty( get_bloginfo( 'description' ) ) ) : ?>
4247
<h2 class="site-description"><?php bloginfo( 'description' ); ?></h2>
48+
<?php endif; ?>
4349
</hgroup>
4450

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

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,11 @@ 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+
// Skip rendering if site title is empty
67+
if ( empty( $site_title ) ) {
68+
return '';
69+
}
70+
6671
$contents = sprintf( $args['title'], esc_url( get_home_url( null, '/' ) ), esc_html( $site_title ) );
6772
if (
6873
( is_front_page() || is_home() && ( (int) get_option( 'page_for_posts' ) !== get_queried_object_id() ) )

0 commit comments

Comments
 (0)