Skip to content

Instantly share code, notes, and snippets.

@tomaskavalek
Last active September 5, 2018 01:57
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tomaskavalek/f2970de5df3c0a43b3fa7c74dbf6e9fb to your computer and use it in GitHub Desktop.
Save tomaskavalek/f2970de5df3c0a43b3fa7c74dbf6e9fb to your computer and use it in GitHub Desktop.
Wordpress – Customize archive page title for selected post type
<?php
/**
* @param $title
* @return array
*/
function archive_titles($title): array
{
global $post;
if ( ! isset($post->post_type)) {
return $title;
}
$type = $post->post_type;
$types = [
'custom_post_type' => 'Custom title',
];
if (is_archive() && isset($types[$type])) {
$title['title'] = $types[$type];
}
return $title;
}
add_filter('document_title_parts', 'archive_titles');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment