post_type_archive_title

Display or retrieve title for a post type archive.

Description

(string|void) post_type_archive_title( (string) $prefix = '', (bool) $display = true ); 

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

Returns (string|void)

Title when retrieving, null when displaying or failure.

Parameters (2)

0. $prefix — Optional. (string) => ''
What to display before the title.
1. $display — Optional. (bool) => true
Optional, default is true. Whether to display or retrieve title.

Usage

  1. if ( !function_exists( 'post_type_archive_title' ) ) { 
  2. require_once ABSPATH . WPINC . '/general-template.php'; 
  3.  
  4. // Optional. What to display before the title. 
  5. $prefix = ''; 
  6.  
  7. // Optional, default is true. Whether to display or retrieve title. 
  8. $display = true; 
  9.  
  10. // NOTICE! Understand what this does before running. 
  11. $result = post_type_archive_title($prefix, $display); 
  12.  

Defined (1)

The function is defined in the following location(s).

/wp-includes/general-template.php  
  1. function post_type_archive_title( $prefix = '', $display = true ) { 
  2. if ( ! is_post_type_archive() ) 
  3. return; 
  4.  
  5. $post_type = get_query_var( 'post_type' ); 
  6. if ( is_array( $post_type ) ) 
  7. $post_type = reset( $post_type ); 
  8.  
  9. $post_type_obj = get_post_type_object( $post_type ); 
  10.  
  11. /** 
  12. * Filters the post type archive title. 
  13. * @since 3.1.0 
  14. * @param string $post_type_name Post type 'name' label. 
  15. * @param string $post_type Post type. 
  16. */ 
  17. $title = apply_filters( 'post_type_archive_title', $post_type_obj->labels->name, $post_type ); 
  18.  
  19. if ( $display ) 
  20. echo $prefix . $title; 
  21. else 
  22. return $prefix . $title;