Skip to content

Instantly share code, notes, and snippets.

@lithiumlab
Last active January 23, 2019 19:00
Show Gist options
  • Save lithiumlab/110b5d46aa2bf8f280e2154dd0ffb4d6 to your computer and use it in GitHub Desktop.
Save lithiumlab/110b5d46aa2bf8f280e2154dd0ffb4d6 to your computer and use it in GitHub Desktop.
WP Conditional page Title Update
<?php
// probably in functions.php ....
add_filter('wp_title', 'thisdomain_news_archive_title');
function thisdomain_news_archive_title($title) {
//check if its a blog post
if (!is_single())
return $title;
//if you get here then its a blog post so change the title
global $wp_query;
if (isset($wp_query->post->post_title)){
// update here to what you need
return $wp_query->post->post_title;
}
//if wordpress can't find the title return the default
return $title;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment