WordPress post_type_archive_title() Function

Beginner
4 min read
Updated: Nov 2026
3 examples
Archive title

Definition

In WordPress, post_type_archive_title() shows the name of a custom post type archive, such as "Books" or "Products".

It only works on a post type archive page. On any other page it prints nothing. You can check the page first with is_post_type_archive().

Syntax

Use it in an archive template for a custom post type.

WordPress
<?php
post_type_archive_title();
CallWhat it does
post_type_archive_title()Prints the post type name.
post_type_archive_title( 'All ' )Prints the name with a prefix.
post_type_archive_title( '', false )Returns the name instead of printing.

The name comes from the labels of the post type.

Full declaration
WordPress
post_type_archive_title( string $prefix = '', bool $display = true ): string|void

Parameters

ParameterDescription
$prefixstring. Text to print before the title. Default is empty.
$displaybool. true (default) prints the title. false returns it.

Return Value

Return ValueDescription
voidWhen $display is true, the title is printed. Nothing is returned.
stringWhen $display is false, the title is returned (without the prefix).

WordPress Examples

Three short theme examples. Each one shows the code and what it prints.

Example 1 — Archive page heading

Use it as the page title in archive-book.php.

WordPress
<h1><?php post_type_archive_title(); ?></h1>

How It Works

  1. The current page is the archive of the book post type.
  2. The function prints the plural label, "Books".
  3. It goes inside the h1.

Example 2 — Add a prefix

Print "Browse: Books".

WordPress
<h1><?php post_type_archive_title( 'Browse: ' ); ?></h1>

How It Works

  1. The first argument is printed before the name.
  2. Remember to add the space yourself.
  3. The result is a friendly heading.

Example 3 — Return the title

Use the title in a variable.

WordPress
<?php
if ( is_post_type_archive() ) {
  $name = post_type_archive_title( '', false );
  echo 'You are viewing: ' . esc_html( $name );
}

How It Works

  1. is_post_type_archive() checks the page type first.
  2. false tells the function to return the title.
  3. We escape and print it ourselves.

Frequently Asked Questions

It prints or returns the name of a custom post type archive, such as Books.
Only on a post type archive page. Elsewhere it prints nothing.
No. The prefix is only added when the title is printed.
From the post type label that you set in register_post_type().

Next: single_cat_title()

Print or return the name of the current category on a category archive.

single_cat_title() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

12 people found this page helpful