The get_the_archive_description WordPress PHP filter allows you to modify the archive description before it is displayed on your website.
Usage
add_filter( 'get_the_archive_description', 'your_custom_function', 10, 1 ); function your_custom_function( $description ) { // your custom code here return $description; }
Parameters
$description
(string) – The archive description to be modified or replaced.
More information
See WordPress Developer Resources: get_the_archive_description
Examples
Add a custom prefix to archive descriptions
Adds a custom prefix to the archive description.
add_filter( 'get_the_archive_description', 'add_custom_prefix', 10, 1 ); function add_custom_prefix( $description ) { $prefix = '**Custom Prefix:** '; return $prefix . $description; }
Remove specific words from archive descriptions
Remove the words “example” and “test” from archive descriptions.
add_filter( 'get_the_archive_description', 'remove_specific_words', 10, 1 ); function remove_specific_words( $description ) { $remove_words = array( 'example', 'test' ); $description = str_replace( $remove_words, '', $description ); return $description; }
Shorten archive descriptions to a specific length
Shortens the archive description to 100 characters.
add_filter( 'get_the_archive_description', 'shorten_description', 10, 1 ); function shorten_description( $description ) { $max_length = 100; return substr( $description, 0, $max_length ); }
Change archive description font style
Wrap the archive description in a <span>
with custom inline CSS.
add_filter( 'get_the_archive_description', 'change_font_style', 10, 1 ); function change_font_style( $description ) { return '<span style="font-style:italic;">' . $description . '</span>'; }
Add a custom message to empty archive descriptions
Displays a custom message when the archive description is empty.
add_filter( 'get_the_archive_description', 'custom_empty_description', 10, 1 ); function custom_empty_description( $description ) { if ( empty( $description ) ) { $description = 'No description available for this archive.'; } return $description; }