Using WordPress ‘post_type_archive_title()’ PHP function

The post_type_archive_title() WordPress PHP function displays or retrieves the title for a post type archive.

Usage

post_type_archive_title( $prefix, $display );

Custom Example:

post_type_archive_title('Archives: ', true);

Output:

Archives: Custom Post Type

Parameters

  • $prefix (string) – Optional. What to display before the title. Default: ”
  • $display (bool) – Optional. Whether to display or retrieve the title. Default: true

More information

See WordPress Developer Resources: post_type_archive_title()

Examples

Displaying the post type archive title without prefix

Display the Custom Post Type title without any prefix.

post_type_archive_title('', true);

Displaying the post type archive title with a custom prefix

Display the Custom Post Type title with a custom prefix “Our “.

post_type_archive_title('Our ', true);

Retrieving the post type archive title without displaying

Retrieve the Custom Post Type title without displaying it, and store it in a variable $title.

$title = post_type_archive_title('', false);

Displaying the post type archive title in an H2 tag with a custom prefix

Display the Custom Post Type title within an H2 tag with a custom prefix “Category: “.

echo '<h2>';
post_type_archive_title('Category: ', true);
echo '</h2>';

Combining post type archive title with additional text

Retrieve the Custom Post Type title, store it in a variable $title, and concatenate additional text before displaying it.

$title = post_type_archive_title('', false);
echo 'Welcome to the ' . $title . ' page!';