post_type_archive_title() WordPress Function

The post_type_archive_title() function is a WordPress function that allows you to display the post type archive title. This function is useful for displaying the title of the post type archive on your website.

post_type_archive_title( string $prefix = '', bool $display = true ) #

Display or retrieve title for a post type archive.


Description

This is optimized for archive.php and archive-{$post_type}.php template files for displaying the title of the post type.


Top ↑

Parameters

$prefix

(string)(Optional) What to display before the title.

Default value: ''

$display

(bool)(Optional) Whether to display or retrieve title.

Default value: true


Top ↑

Return

(string|void) Title when retrieving, null when displaying or failure.


Top ↑

Source

File: wp-includes/general-template.php

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;
	}
}


Top ↑

Changelog

Changelog
VersionDescription
3.1.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.

Show More
Show More