Created
September 15, 2016 09:43
-
-
Save benjibee/9d1eac586a08fdd31e78bf5740a8e7ca to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* | |
* NOT YET IMPLEMENTED FUNCTIONALITY!! EEEEEEP!!!! | |
* | |
* Taken from ticket: #16784 | |
* https://core.trac.wordpress.org/attachment/ticket/16784/16784.diff | |
* | |
* NOT YET IMPLEMENTED FUNCTIONALITY!! EEEEEEP!!!! | |
* | |
* | |
* Display or retrieve description for a post type archive. | |
* | |
* This is optimized for archive.php and archive-{$post_type}.php template files | |
* for displaying the description of the post type. | |
* | |
* @since 4.4.0 | |
* | |
* @param bool $display Optional, default is true. Whether to display or retrieve description. | |
* @return string|null Description when retrieving, null when displaying or failure. | |
*/ | |
function post_type_archive_description( $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 ); | |
/** | |
* Filter the post type archive description. | |
* | |
* @since 4.4.0 | |
* | |
* @param string $post_type_description Post type 'description' argument. | |
* @param string $post_type Post type. | |
*/ | |
$description = apply_filters( 'post_type_archive_description', $post_type_obj->description, $post_type ); | |
if ( $display ) { | |
echo $description; | |
} else { | |
return $description; | |
} | |
} | |
/* | |
* | |
* Taken from old open ticket: #34656 | |
* https://core.trac.wordpress.org/attachment/ticket/34656/34656.diff | |
* | |
* This may not work forever, if these tickets are implemented into core. | |
* ¡¡ Be aware !! | |
* | |
*/ | |
function tip_get_the_archive_description() { | |
$description = ''; | |
if ( is_post_type_archive() ) { | |
$description = post_type_archive_description( '', false ); | |
} else { | |
$description = term_description(); | |
} | |
return $description; | |
} | |
add_action( 'get_the_archive_description', 'tip_get_the_archive_description' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The idea of this function / filter is to display the description given when registering a custom post type on the
archives.php
page by default using the standardthe_archive_description()
.