Created
October 4, 2011 23:58
-
-
Save philipdowner/1263202 to your computer and use it in GitHub Desktop.
Modify the title tag of a WordPress custom post type archive
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
add_filter('wp_title', 'archive_titles'); | |
/** | |
* Modify <title> if on an archive page. | |
* | |
* @author Philip Downer <[email protected]> | |
* @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
wp_title filter is deprecated since WordPress 4.4 (see here). You can use document_title_parts instead.