post_type_archive_title( string $prefix = ”, bool $display = true )
Display or retrieve title for a post type archive.
Description Description
This is optimized for archive.php and archive-{$post_type}.php template files for displaying the title of the post type.
Parameters Parameters
- $prefix
-
(string) (Optional) What to display before the title.
Default value: ”
- $display
-
(bool) (Optional) Whether to display or retrieve title.
Default value: true
Return Return
(string|void) Title when retrieving, null when displaying or failure.
Source Source
File: wp-includes/general-template.php
1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 |
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 ; } } |
Expand full source code View on Trac
Changelog Changelog
Version | Description |
---|---|
3.1.0 | Introduced. |