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
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"
For google search on wordpress wp_title empty this is the first result. So I thought that I might share the most elegant solution for this.
In functions.php add a filter for wp_title.
function custom_wp_title( $title, $sep ) {
if ( is_feed() ) {
return $title;
}
global $page, $paged;
// Add the blog name
$title .= get_bloginfo( 'name', 'display' );
// Add the blog description for the home/front page.
$site_description = get_bloginfo( 'description', 'display' );
if ( $site_description && ( is_home() || is_front_page() ) ) {
$title .= " $sep $site_description";
}
// Add a page number if necessary:
if ( ( $paged >= 2 || $page >= 2 ) && ! is_404() ) {
$title .= " $sep " . sprintf( __( 'Page %s', '_s' ), max( $paged, $page ) );
}
return $title;
}
add_filter( 'wp_title', 'custom_wp_title', 10, 2 );
Late to the conversation...
But if you want to use the actual title of the page that you are using for the static front page, you can use the following:
if (is_front_page())
{
$title = single_post_title( '', false );
}
Although, in the actual source for wp_title(), there is the following, specificaly disabling this for the static front page:
if ( is_single() || ( is_home() && ! is_front_page() ) || ( is_page() && ! is_front_page() ) ) {
$title = single_post_title( '', false );
}
I suspect there is good reason for this. So, proceed with caution.
My 2 cents for "misty lake" theme which had no title on home page and added incorrect title on all other pages.
Just removing the following line from header.php solves the issue, since Wordpress now injects the tag by itself:
<title><?php wp_title( '|', true, 'right' ); ?></title>
I consulted the following page – https://make.wordpress.org/themes/2015/08/25/title-tag-support-now-required/
I use this one and it never failed:
function pageTitle($echo){
$title = "";
global $paged;
if (function_exists('is_tag') && is_tag()) {
$title .= single_tag_title(__("Tag Archive for "" , 'circle'),false);
$title .= '" - ';
}
elseif (is_archive()) {
$title .= wp_title('',true);
//$title .= __(' Archive - ' , 'circle');
$title .= __(' - ' , 'circle');
}
elseif (is_search()) {
$title .= __('Search for "' , 'circle') . esc_html(get_search_query()).'" - ';
}
elseif (!(is_404()) && (is_single()) || (is_page())) {
$title .= wp_title('',true);
$title .= ' - ';
}
elseif (is_404()) {
$title .= __('Not Found - ' , 'circle');
}
if (is_home()) {
$title .= get_bloginfo('name');
$title .= ' - ';
$title .= get_bloginfo('description');
}
else {
$title .= get_bloginfo('name');
}
if ($paged>1) {
$title .= ' - page ' . $paged;
}
if ( !$echo ) return $title;
echo $title;
}
Note that there are translation domains in it that you might want to change.
You could also put something like this inside your title tag:
<?php
if (is_front_page()) { ?>
Home | <?php bloginfo('description');
} else {
wp_title('|', 'true', 'right'); bloginfo('description');
} ?>