WordPress theme homepage logo has h1 tags, what should I do if there are 2 h1s in the category & article pages?

WordpressThe theme homepage logo has an h1 tag, and there are 2 h1s on the category & article inner pages. What should I do?

Internet marketingThere are many methods, includingSEOMost effective and great fornew mediapeople doPublic account promotionstrategy.

Website optimization conforms to webpage html code specifications:

  • The title tag of the page title has the highest weight, followed by the h1 tag.
  • The title and h1 tags should only appear once per page, and if they appear multiple times, they may be penalized by search engines.

As with many WordPress themes, it is common to add h1 tags to the logo in the header.

At the same time, the title of the inner page of the article has an h1 tag, so there will be two h2 tags. How to make each page only have one h1 tag?

I am optimizingChen WeiliangIn the process of blogging, I also encountered such problems. The solution can be modified according to the situation of its own WP theme, referring to the following code:

Modification method 1

Put the code in the header.php file ▼

<hgroup class=”logo-site”></hgroup>

Replace with the following code to solve ▼

<? php 
if (is_home()) {
 echo '<h1 class="site-title">';
}else{
 echo '<div class="h1_logo" >';
}
?>
 <a href="/en/"><img src="<?php bloginfo('template_url'); ?>/img/logo.png" alt="<?php bloginfo('name');?>" title="<?php bloginfo('name');?>" /></a>
<?php 
if (is_home()) {
 echo '</h1>';
}else{
 echo '</div>';
}
?>
  • is_home() The function judges that if it is the home page, it will display the h1 tag, and if it is not the home page, it will display the div tag.

(Since not every WP theme code is the same, ifModification method 1Not applicable, please refer to the followingModification method 2

Modification method 2

WP homepage and category page judgment function description ▼

if ( is_front_page() || is_category() || is_home() ) : ?> 
  • is_front_page and is_home indicate if it is the home page.
  • is_category indicates if it is a category page.

Because only the homepage logo needs to have h1 tags, other pages do not need to have h1 tags.

The following is deleted is_category() ||code after ▼

<? php if (zm_get_option("logo_css")) { ?>
 <div class="logo-site">
 <?php } else { ?>
 <div class="logo-sites">
 <?php } ?>
 <?php
 if ( is_front_page() || is_home() ) : ?> 
 <?php if (zm_get_option('logos')) { ?>
 <h1 class="site-title">
 <?php if ( zm_get_option('logo') ) { ?>
 <a href="<?php echo esc_url( home_url('/') ); ?>"><img src="<?php echo zm_get_option('logo'); ?>" title="<?php echo esc_attr( get_bloginfo( 'name', 'display' ) ); ?>" alt="<?php bloginfo( 'name' ); ?>" rel="home" /><span class="site-name"><?php bloginfo( 'name' ); ?></span></a>
 <?php } ?>
 </h1>
 <?php } else { ?>
 <h1 class="site-title"><a href="<?php echo esc_url( home_url( '/' ) ); ?>" title="<?php echo esc_attr( get_bloginfo( 'name', 'display' ) ); ?>" rel="home"><?php bloginfo( 'name' ); ?></a></h1>
 <p class="site-description"><?php bloginfo( 'description' ); ?></p>
 <?php } ?>
 <?php else : ?>
 <?php if (zm_get_option('logos')) { ?>
 <p class="site-title">
 <?php if ( zm_get_option('logo') ) { ?>
 <a href="<?php echo esc_url( home_url('/') ); ?>"><img src="<?php echo zm_get_option('logo'); ?>" title="<?php echo esc_attr( get_bloginfo( 'name', 'display' ) ); ?>" alt="<?php bloginfo( 'name' ); ?>" rel="home" /><span class="site-name"><?php bloginfo( 'name' ); ?></span></a>
 <?php } ?>
 </p>
 <?php } else { ?>
 <p class="site-title"><a href="<?php echo esc_url( home_url( '/' ) ); ?>" title="<?php echo esc_attr( get_bloginfo( 'name', 'display' ) ); ?>" rel="home"><?php bloginfo( 'name' ); ?></a></p>
 <p class="site-description"><?php bloginfo( 'description' ); ?></p>
 <?php } ?>
 <?php endif;
 ?>
  • if ( is_front_page() || is_home() ) : ?>  <?php if (zm_get_option('logos')) { ?>Indicates that if the home page has a logo setting, the logo with the h1 tag will be displayed.
  • 1th <?php else : ?> Indicates that if there is no logo, the site title and subtitle (with h1 tags) in "Settings" will be displayed.
  • 2th <?php else : ?> <?php if (zm_get_option('logos')) { ?> Indicates that if it is not the home page, the logo without the h1 tag will be displayed.
  • 3th <?php else : ?>Indicates that if it is not the home page and has no logo, the website title and subtitle in "Settings" will be displayed.

Add category page title h1 code

If the logo of your category page does not output the h1 tag, and the category page template does not have the h1 title tag...

(specific situation,Google ChromePress CTRL + U Find webpage code<h1to make sure)

first step:Determine the category page, there is no h1 tag at all, you need to add the "category page h1 title" code in the category page template ▼

<h1 class="cat_title"><?php single_cat_title(); ?></h1>

The second step:In the style.css file, add the CSS style code for the h1 title of the category page ▼

h1.cat_title{
 background: #fff;
 text-align: left;
 font: 18px "Open Sans", Arial, sans-serif;
 text-transform: uppercase;
 border-radius: 2px;
 border-left: 10px solid #0373db;
 padding-left: 14px;
 margin: 0 0 8px 0;
 line-height: 2;
}

After this modification, you can easily solve the problem that the website logo has h1 tags, and the inner page articles and category pages have 2 h1 tags.

SEO is the result of optimization of various details. If you can optimize various details of various website codes, website ranking will also be improved to a certain extent ^_^

Comment

Your email address will not be published. Required fields * Callout

Scroll to Top