post_type_archive_title

The timeline below displays how wordpress function post_type_archive_title has changed across different WordPress versions. If a version is not listed, refer to the next available version below.

WordPress Version: 6.1

/**
 * Displays or retrieves title for a post type archive.
 *
 * This is optimized for archive.php and archive-{$post_type}.php template files
 * for displaying the title of the post type.
 *
 * @since 3.1.0
 *
 * @param string $prefix  Optional. What to display before the title.
 * @param bool   $display Optional. Whether to display or retrieve title. Default true.
 * @return string|void Title when retrieving, null when displaying or failure.
 */
function post_type_archive_title($prefix = '', $display = true)
{
    if (!is_post_type_archive()) {
        return;
    }
    $post_type = get_query_var('post_type');
    if (is_array($post_type)) {
        $post_type = reset($post_type);
    }
    $post_type_obj = get_post_type_object($post_type);
    /**
     * Filters the post type archive title.
     *
     * @since 3.1.0
     *
     * @param string $post_type_name Post type 'name' label.
     * @param string $post_type      Post type.
     */
    $title = apply_filters('post_type_archive_title', $post_type_obj->labels->name, $post_type);
    if ($display) {
        echo $prefix . $title;
    } else {
        return $prefix . $title;
    }
}

WordPress Version: 5.5

/**
 * Display or retrieve title for a post type archive.
 *
 * This is optimized for archive.php and archive-{$post_type}.php template files
 * for displaying the title of the post type.
 *
 * @since 3.1.0
 *
 * @param string $prefix  Optional. What to display before the title.
 * @param bool   $display Optional. Whether to display or retrieve title. Default true.
 * @return string|void Title when retrieving, null when displaying or failure.
 */
function post_type_archive_title($prefix = '', $display = true)
{
    if (!is_post_type_archive()) {
        return;
    }
    $post_type = get_query_var('post_type');
    if (is_array($post_type)) {
        $post_type = reset($post_type);
    }
    $post_type_obj = get_post_type_object($post_type);
    /**
     * Filters the post type archive title.
     *
     * @since 3.1.0
     *
     * @param string $post_type_name Post type 'name' label.
     * @param string $post_type      Post type.
     */
    $title = apply_filters('post_type_archive_title', $post_type_obj->labels->name, $post_type);
    if ($display) {
        echo $prefix . $title;
    } else {
        return $prefix . $title;
    }
}

WordPress Version: 4.6

/**
 * Display or retrieve title for a post type archive.
 *
 * This is optimized for archive.php and archive-{$post_type}.php template files
 * for displaying the title of the post type.
 *
 * @since 3.1.0
 *
 * @param string $prefix  Optional. What to display before the title.
 * @param bool   $display Optional, default is true. Whether to display or retrieve title.
 * @return string|void Title when retrieving, null when displaying or failure.
 */
function post_type_archive_title($prefix = '', $display = true)
{
    if (!is_post_type_archive()) {
        return;
    }
    $post_type = get_query_var('post_type');
    if (is_array($post_type)) {
        $post_type = reset($post_type);
    }
    $post_type_obj = get_post_type_object($post_type);
    /**
     * Filters the post type archive title.
     *
     * @since 3.1.0
     *
     * @param string $post_type_name Post type 'name' label.
     * @param string $post_type      Post type.
     */
    $title = apply_filters('post_type_archive_title', $post_type_obj->labels->name, $post_type);
    if ($display) {
        echo $prefix . $title;
    } else {
        return $prefix . $title;
    }
}

WordPress Version: 4.3

/**
 * Display or retrieve title for a post type archive.
 *
 * This is optimized for archive.php and archive-{$post_type}.php template files
 * for displaying the title of the post type.
 *
 * @since 3.1.0
 *
 * @param string $prefix  Optional. What to display before the title.
 * @param bool   $display Optional, default is true. Whether to display or retrieve title.
 * @return string|void Title when retrieving, null when displaying or failure.
 */
function post_type_archive_title($prefix = '', $display = true)
{
    if (!is_post_type_archive()) {
        return;
    }
    $post_type = get_query_var('post_type');
    if (is_array($post_type)) {
        $post_type = reset($post_type);
    }
    $post_type_obj = get_post_type_object($post_type);
    /**
     * Filter the post type archive title.
     *
     * @since 3.1.0
     *
     * @param string $post_type_name Post type 'name' label.
     * @param string $post_type      Post type.
     */
    $title = apply_filters('post_type_archive_title', $post_type_obj->labels->name, $post_type);
    if ($display) {
        echo $prefix . $title;
    } else {
        return $prefix . $title;
    }
}

WordPress Version: 3.8

/**
 * Display or retrieve title for a post type archive.
 *
 * This is optimized for archive.php and archive-{$post_type}.php template files
 * for displaying the title of the post type.
 *
 * @since 3.1.0
 *
 * @param string $prefix Optional. What to display before the title.
 * @param bool $display Optional, default is true. Whether to display or retrieve title.
 * @return string|null Title when retrieving, null when displaying or failure.
 */
function post_type_archive_title($prefix = '', $display = true)
{
    if (!is_post_type_archive()) {
        return;
    }
    $post_type = get_query_var('post_type');
    if (is_array($post_type)) {
        $post_type = reset($post_type);
    }
    $post_type_obj = get_post_type_object($post_type);
    /**
     * Filter the post type archive title.
     *
     * @since 3.1.0
     *
     * @param string $post_type_name Post type 'name' label.
     * @param string $post_type      Post type.
     */
    $title = apply_filters('post_type_archive_title', $post_type_obj->labels->name, $post_type);
    if ($display) {
        echo $prefix . $title;
    } else {
        return $prefix . $title;
    }
}

WordPress Version: 3.7

/**
 * Display or retrieve title for a post type archive.
 *
 * This is optimized for archive.php and archive-{$post_type}.php template files
 * for displaying the title of the post type.
 *
 * @since 3.1.0
 *
 * @param string $prefix Optional. What to display before the title.
 * @param bool $display Optional, default is true. Whether to display or retrieve title.
 * @return string|null Title when retrieving, null when displaying or failure.
 */
function post_type_archive_title($prefix = '', $display = true)
{
    if (!is_post_type_archive()) {
        return;
    }
    $post_type = get_query_var('post_type');
    if (is_array($post_type)) {
        $post_type = reset($post_type);
    }
    $post_type_obj = get_post_type_object($post_type);
    $title = apply_filters('post_type_archive_title', $post_type_obj->labels->name);
    if ($display) {
        echo $prefix . $title;
    } else {
        return $prefix . $title;
    }
}