| 1187 | * Display or retrieve description for a post type archive. |
| 1188 | * |
| 1189 | * This is optimized for archive.php and archive-{$post_type}.php template files |
| 1190 | * for displaying the description of the post type. |
| 1191 | * |
| 1192 | * @since 4.4.0 |
| 1193 | * |
| 1194 | * @param string $prefix Optional. What to display before the description. |
| 1195 | * @param bool $display Optional, default is true. Whether to display or retrieve description. |
| 1196 | * @return string|void description when retrieving, null when displaying or failure. |
| 1197 | */ |
| 1198 | function post_type_archive_description( $prefix = '', $display = true ) { |
| 1199 | if ( ! is_post_type_archive() ) |
| 1200 | return; |
| 1201 | |
| 1202 | $post_type = get_query_var( 'post_type' ); |
| 1203 | if ( is_array( $post_type ) ) |
| 1204 | $post_type = reset( $post_type ); |
| 1205 | |
| 1206 | $post_type_obj = get_post_type_object( $post_type ); |
| 1207 | |
| 1208 | /** |
| 1209 | * Filter the post type archive description. |
| 1210 | * |
| 1211 | * @since 3.1.0 |
| 1212 | * |
| 1213 | * @param string $post_type_name Post type 'name' label. |
| 1214 | * @param string $post_type Post type. |
| 1215 | */ |
| 1216 | $description = apply_filters( 'post_type_archive_description', $post_type_obj->description, $post_type ); |
| 1217 | |
| 1218 | if ( $display ) |
| 1219 | echo $prefix . $description; |
| 1220 | else |
| 1221 | return $prefix . $description; |
| 1222 | } |
| 1223 | |
| 1224 | /** |