WordPress.org

Make WordPress Core

Opened 3 months ago

Last modified 3 months ago

#52404 new enhancement

Fix get_the_archive_description() to support default blog index

Reported by: jaakkosaarenketo Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version: 5.6
Component: General Keywords: has-patch
Focuses: template Cc:

Description

get_the_archive_description() returns nothing when viewing the default blog index.
When viewing a custom post type index, it returns the description parameter but even if I add the description to 'post' nothing is displayed.

The fix requires only adding additional is_home() check to is_post_type_archive() condition in get_the_archive_description() and setting a fallback $post_type = 'post' in get_the_post_type_description().

Note that description for 'post' doesn't exist by default so this shouldn't cause any surprising changes. It just makes the function more logical.

With these to very minor changes, adding archive description for blog index is possible by a filter such as:

function add_description_to_default_archive( $args, $post_type ) {

  if( 'post' == $post_type ) {
    $args['description'] = 'Enjoy our posts!';
  }

  return $args;
}
add_filter( 'register_post_type_args', 'add_description_to_default_archive', 10, 2 );

I'll make a pull request of the changes in github.

Change History (1)

This ticket was mentioned in PR #960 on WordPress/wordpress-develop by Jaska.


3 months ago

  • Keywords has-patch added

get_the_archive_description() returns nothing
when viewing the default blog index.
When viewing a custom post type index, it
returns the description parameter but even if I
add the description to 'post' nothing is displayed.

The fix requires only adding additional
is_home() check to is_post_type_archive()
condition in get_the_archive_description() and
setting a fallback $post_type = 'post' in
get_the_post_type_description().

Note that description for 'post' doesn't exist by
default so this shouldn't cause any surprising
changes. It just makes the function more logical.

With these to very minor changes, adding
archive description for blog index is simple by
filtering 'register_post_type_args'

Trac ticket: https://core.trac.wordpress.org/ticket/52404#ticket

Note: See TracTickets for help on using tickets.