Home › Forums › Back End › WordPress – modify title tag. › Reply To: WordPress – modify title tag.
June 7, 2016 at 1:52 am
#242600
Ilan Firsov
Participant
I think you may be able to use the same logic in the filter you just need to return the new title at the end instead of echoing it
Try this
<?php
add_filter( 'pre_get_document_title', 'my_custom_page_title' );
function my_custom_page_title( $title ) {
global $page, $paged;
// Add the site name and separator.
$new_title = get_bloginfo('name') . ' | ';
// Add the site description for the front page.
$site_description = get_bloginfo('description', 'display');
if ($site_description && (is_front_page())) $new_title .= $site_description;
// Show page title on posts page.
if (is_home()) $new_title .= $title;
// Title for 404.
if (is_404()) $new_title .= 'file not available';
// Add a page number if necessary:
if ($paged >= 2 || $page >= 2 ) $new_title .= ' ' . sprintf( __('(page %s)'), max($paged, $page) );
// Show page title.
if (is_page()) $new_title .= $title;
return $new_title;
}