Using conditional titles with title-tag rather than wp_title(), how do I add the immediate parent or ultimate grandparent to the title and,for multi-paged posts, the page number?

When using wp_title(), this added page numbers to multi-page posts:

if ($paged >= 2 || $page >= 2 ) echo ' ' . sprintf( __('(page %s)'), max($paged, $page) );

It doesn't work with title-tag. And I've never known how to prepend with parent/grandparent

  • What is a "conditional title"?
    – fuxia
    Jun 2, 2016 at 12:03
  • Conditional titles are where the html title is changed according to various conditions. Typically it's done for SEO.
    – gulliver
    Jun 3, 2016 at 5:09
  • wp_title() does that too. Please show us your exact code.
    – fuxia
    Jun 3, 2016 at 5:24
  • @toscho... wp_title() is due to be deprecated, hence my switch. I've updated the original question to include existing code.
    – gulliver
    Jun 3, 2016 at 13:18

1 Answer 1


You should be able to hook into the title by using wp_title filter

function se_custom_title( $title ) {
 if(x == y) {   
  $title = 'something'. $title;
 return $title;
add_filter( 'wp_title', 'se_custom_titles' );

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.