The get_the_post_type_description WordPress PHP filter allows you to modify the description for a post type archive.
Usage
add_filter('get_the_post_type_description', 'your_custom_function', 10, 2);
function your_custom_function($description, $post_type_obj) {
// your custom code here
return $description;
}
Parameters
$description(string) – The post type description.$post_type_obj(WP_Post_Type) – The post type object.
More information
See WordPress Developer Resources: get_the_post_type_description
Examples
Change description for a specific post type
Update the description for a custom post type called ‘product’.
add_filter('get_the_post_type_description', 'change_product_description', 10, 2);
function change_product_description($description, $post_type_obj) {
if ('product' === $post_type_obj->name) {
$description = 'This is an updated description for the product post type.';
}
return $description;
}
Add a prefix to all post type descriptions
Add a prefix to the description for all post type archives.
add_filter('get_the_post_type_description', 'add_description_prefix', 10, 2);
function add_description_prefix($description, $post_type_obj) {
$prefix = 'Archive: ';
return $prefix . $description;
}
Remove post type descriptions
Remove the description for all post type archives.
add_filter('get_the_post_type_description', 'remove_post_type_descriptions', 10, 2);
function remove_post_type_descriptions($description, $post_type_obj) {
return '';
}
Append custom text to post type descriptions
Add custom text to the end of the description for all post type archives.
add_filter('get_the_post_type_description', 'append_custom_text', 10, 2);
function append_custom_text($description, $post_type_obj) {
$custom_text = ' Browse our collection.';
return $description . $custom_text;
}
Modify post type description based on user role
Change the description for a custom post type called ‘event’ based on the user’s role.
add_filter('get_the_post_type_description', 'change_event_description_for_users', 10, 2);
function change_event_description_for_users($description, $post_type_obj) {
if ('event' === $post_type_obj->name) {
$user = wp_get_current_user();
if (in_array('administrator', $user->roles)) {
$description = 'Welcome, admin! This is the event post type.';
} else {
$description = 'Welcome, user! This is the event post type.';
}
}
return $description;
}