Make WordPress Core

Opened 5 years ago

Last modified 7 months ago

#48804 new enhancement

Twenty Twenty: Attach template parts with actions instead of directly including

Reported by: ianbelanger's profile ianbelanger Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version: 5.3
Component: Bundled Theme Keywords: dev-feedback
Focuses: Cc:

Description

Originally requested on GitHub by @thomasplevy

https://github.com/WordPress/twentytwenty/issues/947

The Problem

Not all custom post types are created equal. Some custom post types are like blog posts where meta information, post author information, and navigation between post types makes sense. Other custom post types behave more like native pages where navigation between pages is undesirable.

This is a pretty generic and blanket statement and it's not always true. Custom post types are custom and the requirement differ greatly depending on the developer creating them.

I am working to add Twenty Twenty theme support for my plugin [LifterLMS](https://github.com/gocodebox/lifterlms) and I have several custom post types which I'd like to be able to remove author and custom post type navigation for.

Given the fact that custom post types utilize template at template-parts/content.php it is currently only possible for me to remove the navigation and author information by using custom CSS.

The meta information I am able to disable using the filter twentytwenty_disallowed_post_types_for_meta_output.

Proposed Solution

I'd like to modify the template in question to either be wrapped in a filter which allow the inclusion of template-parts/entry-author-bio.php and template-parts/navigation.php to be disabled via a filter.

For example:

https://github.com/WordPress/twentytwenty/blob/dea9290e7ca3d38b7067c3b7107787db6554249a/template-parts/content.php#L68-L72

if ( is_single() ) { 
  
    get_template_part( 'template-parts/navigation' ); 
  
} 

Could become:

if ( is_single() && apply_filters( 'twentytwenty_display_single_navigation', true ) ) {
    get_template_part( 'template-parts/navigation' );
}

If this does seem like an acceptable addition I'd be more than happy to write and submit the PR but I didn't want to spend time without a blessing from a core contrib or maintainer first.

Thank you for considering this!

Change History (3)

#1 @joyously
5 years ago

As commented on GitHub:
It makes sense to me to put the checks into the individual template files instead of in content.php and duplicated in content-cover.php and that is called with a post type parameter, so it could be any other post type also, in a child theme.
The part for the author bio should check for post type support, and a filter is always useful.
So instead of

if ( is_single() ) {
	get_template_part( 'template-parts/entry-author-bio' );
}

the template part should be unconditional and there should be a check inside the author-bio template like

$this_post_type = get_post_type();
if ( post_type_supports( $this_post_type, 'author' ) &&
	! in_array( $this_post_type, apply_filters( 'twentytwenty_posttypes_no_author', array( 'page' ) ) ) ) {
	if ( is_attachment() || is_single() )

(This is actually code I have in my theme.)

#2 @karmatosed
8 months ago

  • Keywords dev-feedback added

#3 @karmatosed
7 months ago

  • Keywords 2nd-opinion removed
Note: See TracTickets for help on using tickets.