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.
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 thewp_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.
But if you use a static home page, this is the code:
<title><?php bloginfo('name'); ?> » <?php is_front_page() ? bloginfo('description') : wp_title(''); ?></title>
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...
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"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With