Skip to content

Instantly share code, notes, and snippets.

@bondarolik
Created August 30, 2012 03:17
Show Gist options
  • Save bondarolik/3521986 to your computer and use it in GitHub Desktop.
Save bondarolik/3521986 to your computer and use it in GitHub Desktop.
Better SEO wp_title()
# Rewrite <title> tag for better SEO
function seo_title() {
global $post, $page, $paged;
$sep = " | "; # Separator
$newtitle = get_bloginfo('name'); # Default
# Single page ########################################
if (is_single() || is_page()) {
$newtitle = single_post_title("", false); # default title
}
# Category ########################################
if (is_category())
$newtitle = single_cat_title("", false);
# Tag ########################################
if (is_tag())
$newtitle = single_tag_title("", false);
# Search results ########################################
if (is_search())
$newtitle = "Результаты поиска: " . $s;
# Taxonomy page ########################################
if (is_tax()) {
$curr_tax = get_taxonomy(get_query_var('taxonomy'));
$curr_term = get_term_by('slug', get_query_var('term'), get_query_var('taxonomy')); # current term data
# if it's term
if (!empty($curr_term)) {
$newtitle = $curr_tax->label . $sep . $curr_term->name;
} else {
$newtitle = $curr_tax->label;
}
}
# Add page number if necesary
if ($paged >= 2 || $page >= 2)
$newtitle .= $sep . sprintf('Страница %s', max($paged, $page));
# Home & Front Page ########################################
if (is_home() || is_front_page()) {
$newtitle = get_bloginfo('name') . $sep . get_bloginfo('description');
} else {
$newtitle .= " | " . get_bloginfo('name');
}
return $newtitle;
}
add_filter('wp_title', 'seo_title');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment