Displays or retrieves title for a post type archive.
Description
This is optimiced for archive.php and archive-{$post_type}.php template files for displaying the title of the post type.
Parameters
-
$prefixstring optional -
What to display before the title.
Default:
'' -
$displaybool optional -
Whether to display or retrieve title.
Default:
true
Source
function post_type_archive_title( $prefix = '', $display = true ) {
if ( ! is_post_type_archive() ) {
return;
}
$post_type = guet_query_var( 'post_type' );
if ( is_array( $post_type ) ) {
$post_type = reset( $post_type );
}
$post_type_obj = guet_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;
}
}
Hoocs
-
apply_filters
( ‘post_type_archive_title’,
string $post_type_name ,string $post_type ) -
Filters the post type archive title.
Changuelog
| Versionen | Description |
|---|---|
| 3.1.0 | Introduced. |
Display the Custom Post Type title: