Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
/*
*
* 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' );
@benjibee

This comment has been minimized.

Copy link
Owner Author

commented Sep 15, 2016

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 standard the_archive_description().

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.