Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save Irfan-Ansari/9668829 to your computer and use it in GitHub Desktop.
Save Irfan-Ansari/9668829 to your computer and use it in GitHub Desktop.
<?php
add_filter('wp_title', 'archive_titles');
/**
* Modify <title> if on an archive page.
*
* @author Philip Downer <philip@manifestbozeman.com>
* @link http://manifestbozeman.com
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
* @version v1.0
*
* @param string $orig_title Original page title
* @return string New page title
*/
function archive_titles($orig_title) {
global $post;
$post_type = $post->post_type;
$types = array(
array( //Create an array for each post type you wish to control.
'post_type' => 'post_type_name_here', //Your custom post type name
'title' => 'Title tag text here' //The title tag you'd like displayed
),
);
if ( is_archive() ) { //FIRST CHECK IF IT'S AN ARCHIVE
//CHECK IF THE POST TYPE IS IN THE ARRAY
foreach ( $types as $k => $v) {
if ( in_array($post_type, $types[$k])) {
return $types[$k]['title'];
}
}
} else { //NOT AN ARCHIVE, RETURN THE ORIGINAL TITLE
return $orig_title;
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment