WordPress.org

Make WordPress Core

Opened 8 months ago

Last modified 8 months ago

#45955 new enhancement

Twenty Nineteen: get_the_archive_title filter issues

Reported by: taskotr Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version:
Component: Bundled Theme Keywords: dev-feedback 2nd-opinion has-patch
Focuses: Cc:

Description

I was testing the theme with a plugin that adds a custom post type and allows to set a custom title for the custom post type archive view using the following filter:

add_filter( 'get_the_archive_title', 'slug_set_the_archive_title' );

While this filter works fine in the previous WordPress themes, such as Twenty Seventeen, Twenty Sixteen and Twenty Fifteen, it does not work in Twenty Nineteen.

It's possible to fix it by setting a priority parameter in the filter. For example:

add_filter( 'get_the_archive_title', 'slug_set_the_archive_title', 99 );

The problem is that it breaks a header style, meaning the title will have the style of the archive view prefix text (grey color and serif font style).

Any idea what is the better way to use this filter in the
Twenty Nineteen theme?

Attachments (1)

45955.diff (610 bytes) - added by mukesh27 8 months ago.
Patch to change theme filter priority

Download all attachments as: .zip

Change History (3)

#1 @mukesh27
8 months ago

  • Keywords 2nd-opinion needs-patch added
  • Type changed from defect (bug) to enhancement

Hi @taskotr, Welcome to WordPres Trac! Thanks for the report.

Theme already used add_filter( 'get_the_archive_title', 'twentynineteen_get_the_archive_title' ); archive filter with priority of 10 so if you want to override that filter with your plugin functionality then you have to add high priority then 10 then your filter works in Twenty Nineteen.

For ex.

If you have develop plugin with below filter then add below priority.

add_filter( 'get_the_archive_title', 'slug_set_the_archive_title', 99 );

If you have use any third party plugin and it's filter does not work then remove theme filter using below code.

remove_filter( 'get_the_archive_title', 'twentynineteen_get_the_archive_title' );

For better solution, In Twenty Nineteen theme we needs to change filter priority to 1 instead of 10 so plugin can override filter as per there needs.

Last edited 8 months ago by mukesh27 (previous) (diff)

@mukesh27
8 months ago

Patch to change theme filter priority

#2 @mukesh27
8 months ago

  • Keywords has-patch added; needs-patch removed

Attached patch change filter priority to 1 instead of 10 so plugin can override filter as per there needs.

Note: See TracTickets for help on using tickets.