Skip to content

Commit 7978741

Browse files
committed
refactor: optimize site title/description checks across default themes
1 parent 57fb74d commit 7978741

9 files changed

Lines changed: 77 additions & 57 deletions

File tree

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

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -80,14 +80,18 @@
8080
<hgroup>
8181
<?php
8282
$is_front = ! is_paged() && ( is_front_page() || ( is_home() && ( (int) get_option( 'page_for_posts' ) !== get_queried_object_id() ) ) );
83-
?>
83+
$site_name = get_bloginfo( 'name' );
84+
$site_description = get_bloginfo( 'description' );
8485

85-
<?php if ( ! empty( get_bloginfo( 'name' ) ) ) : ?>
86-
<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' ) ) ) : ?>
90-
<h2 id="site-description"><?php bloginfo( 'description' ); ?></h2>
86+
if ( $site_name || $site_description ) :
87+
?>
88+
<?php if ( $site_name ) : ?>
89+
<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>
90+
<?php endif; ?>
91+
92+
<?php if ( $site_description ) : ?>
93+
<h2 id="site-description"><?php bloginfo( 'description' ); ?></h2>
94+
<?php endif; ?>
9195
<?php endif; ?>
9296
</hgroup>
9397

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

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,14 @@
3434
<?php
3535
twentyfifteen_the_custom_logo();
3636
$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' );
3738

38-
if ( ! empty( get_bloginfo( 'name' ) ) ) :
39-
if ( is_front_page() && is_home() ) :
40-
?>
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
45-
endif;
39+
if ( $site_name && is_front_page() && is_home() ) :
40+
?>
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 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 bloginfo( 'name' ); ?></a></p>
44+
<?php
4645
endif;
4746

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

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

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

5151
<header id="masthead" class="site-header">
5252
<div class="header-main">
53-
<?php if ( ! empty( get_bloginfo( 'name' ) ) ) : ?>
53+
<?php
54+
$site_name = get_bloginfo( 'name' );
55+
if ( $site_name ) :
56+
?>
5457
<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>
5558
<?php endif; ?>
5659

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

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,16 @@
1717
<div class="site-branding-text">
1818
<?php
1919
$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' );
2021

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;
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 bloginfo( 'name' ); ?></a></h1>
25+
<?php
26+
elseif ( $site_name ) :
27+
?>
28+
<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>
29+
<?php
2930
endif;
3031

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

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

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,16 @@
3838
<?php twentysixteen_the_custom_logo(); ?>
3939
<?php
4040
$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' );
4142

42-
if ( ! empty( get_bloginfo( 'name' ) ) ) :
43-
if ( 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 bloginfo( 'name' ); ?></a></h1>
46-
<?php else : ?>
47-
<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>
48-
<?php
49-
endif;
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 bloginfo( 'name' ); ?></a></h1>
46+
<?php
47+
elseif ( $site_name ) :
48+
?>
49+
<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>
50+
<?php
5051
endif;
5152

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

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

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -71,18 +71,22 @@
7171
<?php
7272
$heading_tag = ( is_home() || is_front_page() ) ? 'h1' : 'div';
7373
$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' ) ) ) : ?>
77-
<<?php echo $heading_tag; ?> id="site-title">
78-
<span>
79-
<a href="<?php echo esc_url( home_url( '/' ) ); ?>" rel="home" <?php echo $is_front ? 'aria-current="page"' : ''; ?>><?php bloginfo( 'name' ); ?></a>
80-
</span>
81-
</<?php echo $heading_tag; ?>>
82-
<?php endif; ?>
74+
$site_name = get_bloginfo( 'name' );
75+
$site_description = get_bloginfo( 'description' );
8376

84-
<?php if ( ! empty( get_bloginfo( 'description' ) ) ) : ?>
85-
<div id="site-description"><?php bloginfo( 'description' ); ?></div>
77+
if ( $site_name || $site_description ) :
78+
?>
79+
<?php if ( $site_name ) : ?>
80+
<<?php echo $heading_tag; ?> id="site-title">
81+
<span>
82+
<a href="<?php echo esc_url( home_url( '/' ) ); ?>" rel="home" <?php echo $is_front ? 'aria-current="page"' : ''; ?>><?php bloginfo( 'name' ); ?></a>
83+
</span>
84+
</<?php echo $heading_tag; ?>>
85+
<?php endif; ?>
86+
87+
<?php if ( $site_description ) : ?>
88+
<div id="site-description"><?php bloginfo( 'description' ); ?></div>
89+
<?php endif; ?>
8690
<?php endif; ?>
8791

8892
<?php

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

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,17 @@
3131
<header id="masthead" class="site-header">
3232
<?php
3333
$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' );
35+
$site_description = get_bloginfo( 'description' );
3436

35-
if ( ! empty( get_bloginfo( 'name' ) ) || ! empty( get_bloginfo( 'description' ) ) ) :
37+
if ( $site_name || $site_description ) :
3638
?>
3739
<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' ) ) ) : ?>
39-
<h1 class="site-title"><?php bloginfo( 'name' ); ?></h1>
40+
<?php if ( $site_name ) : ?>
41+
<h1 class="site-title"><?php bloginfo( 'name' ); ?></h1>
4042
<?php endif; ?>
41-
<?php if ( ! empty( get_bloginfo( 'description' ) ) ) : ?>
42-
<h2 class="site-description"><?php bloginfo( 'description' ); ?></h2>
43+
<?php if ( $site_description ) : ?>
44+
<h2 class="site-description"><?php bloginfo( 'description' ); ?></h2>
4345
<?php endif; ?>
4446
</a>
4547
<?php endif; ?>

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

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,20 @@
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-
42-
<?php if ( ! empty( get_bloginfo( 'name' ) ) ) : ?>
43-
<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' ) ) ) : ?>
47-
<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' );
43+
$site_description = get_bloginfo( 'description' );
44+
45+
if ( $site_name || $site_description ) :
46+
?>
47+
<?php if ( $site_name ) : ?>
48+
<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>
49+
<?php endif; ?>
50+
51+
<?php if ( $site_description ) : ?>
52+
<h2 class="site-description"><?php bloginfo( 'description' ); ?></h2>
53+
<?php endif; ?>
4854
<?php endif; ?>
4955
</hgroup>
5056

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ 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 ( empty( $site_title ) ) {
66+
if ( ! $site_title ) {
6767
return '';
6868
}
6969

0 commit comments

Comments
 (0)