questions

Different title for homepage and single posts in WP

Rate this post

Basically I want to display a different title for my homepage and single posts.

Right now I have this code in the header.php:

<title> <?php wp_title('', true,''); ?> (<?php the_time( 'Y/m/d' ); ?>)- <?php echo get_bloginfo( 'name' ); ?> </title>

This displays my post title, post date and my blog name.

How to make a coffee (2021/02/05) – My Coffee Blog

But when I go to my home page, it displays date first (which I don’t need) and only then my blog name.

(2021/02/05) – My Coffee Blog

Is there any way to control which ones to output for homepage, posts and pages?

Thanks!

 

✔️Solution:

Use is_front_page().

Something like this should work:

<title>  
  <?php 
    if (!(is_front_page())) {
      wp_title('', true,''); ?>  (<?php the_time( 'Y/m/d' ); ?>)- 
    <?php }
  echo get_bloginfo( 'name' ); ?>  
</title>

Leave a Reply

Your email address will not be published.

Back to top button