Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WordPress wp_title blank on index page

I'm new to WordPress and just installed version 3.3.1.

I did some googling regarding this question and found some answers but they were relevant to version 2.7 and were 2-3 years old.

Basically, the wp_title function works fine on every page except my home page where it returns blank and I get no title whatsoever. I could just hard code the title in but I'd rather not do that.

Guilty line of code:

<title><?php wp_title ( '| So Fresh n\' So Clean', true,'right' ); ?></title>

I couldn't find anything regarding this problem happening in 3.3.1 so clearly I've done something wrong.

like image 823
nmford Avatar asked Jan 29 '12 17:01

nmford


4 Answers

Here's is what I read from Codex:

If you are using a custom homepage with custom loops and stuff, you will have an empty wp_title. Here goes a neat hack to add the description/tagline at the wp_title place on homepage:

<title><?php bloginfo('name'); ?> | <?php is_front_page() ? bloginfo('description') : wp_title(''); ?></title>

So use is_front_page() to get the title on homepage, the way it is suggested in above code.

like image 169
Amna Ahmed Avatar answered Oct 19 '22 14:10

Amna Ahmed


But if you use a static home page, this is the code:

<title><?php bloginfo('name'); ?> &raquo; <?php is_front_page() ? bloginfo('description') : wp_title(''); ?></title>
like image 45
danielgc Avatar answered Oct 19 '22 14:10

danielgc


Update for WordPress versions (>= 4.4)

Try this

function some_name(){
    add_theme_support( 'title-tag' );
}

add_action( 'after_setup_theme', 'some_name' );

Do this in functions.php and remove 'title' tag from head...

like image 29
w411 3 Avatar answered Oct 19 '22 13:10

w411 3


Working off of Amna's answer, I came up with the following code which should display the page title when there is one, followed by the site name.

<?php wp_title(' - ',TRUE,'right'); bloginfo('name'); ?>

Post/Page Outputs: "The Page Title - Site Name"

Home Page Outputs: "Site Name"


Obviously, this can also be swapped to display the site name first.

<?php bloginfo('name'); wp_title(' - '); ?>

Post/Page Outputs: "Site Name - The Page Title"

Home Page Outputs: "Site Name"


This can also be combined with a conditional to display the site description when viewing the home page.

<?php bloginfo('name'); echo ' - '; is_front_page() ? bloginfo('description') : wp_title(''); ?>

Post/Page Outputs: "Site Name - The Page Title"

Home Page Outputs: "Site Name - The Site Description"

like image 25
ian.pvd Avatar answered Oct 19 '22 13:10

ian.pvd