naeemqaswar
10/6/2017 - 9:41 AM

Modify Archive Title

Modify the title tag of a WordPress custom post type archive

add_filter('wp_title', 'archive_titles');

/**
* If above filter doesn't modify archive title, then try using it with priority
* add_filter('wp_title', 'archive_titles', 99);
*/

/**
* 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;
	}
}