Make WordPress Core

Opened 7 years ago

Closed 7 years ago

Last modified 7 years ago

#40258 closed enhancement (duplicate)

Add hook for get_template_part

Reported by: tazotodua's profile tazotodua Owned by:
Milestone: Priority: normal
Severity: normal Version:
Component: Themes Keywords:
Focuses: Cc:

Description (last modified by SergeyBiryukov)

We frequently use themes, which themselves use
get_template_part('smth1/smth2')

however, i many cases, we want (from custom plugin) to avoid inclusion of specific template parts.

there seems no solution, rather than manually modifying themes inner code to avoid getting that particular template part.

It will be better if there was a hook:

function get_template_part( $slug, $name = null ) {

    .....
    $slug =apply_filters('get_template_part_filter', $slug, $name);
    if(empty($slug)) return;
    ........
      
}

Change History (3)

#1 @tazotodua
7 years ago

Another problem arises when in theme there is:

get_template_part( 'components/footer/site');

as from [https://core.trac.wordpress.org/browser/tags/4.7/src/wp-includes/general-template.php#L158 ):

it becomes:
add_action('get_template_part_components/footer/site'

and I think slash there is not a good idea.

Last edited 7 years ago by tazotodua (previous) (diff)

#2 @swissspidy
7 years ago

  • Milestone Awaiting Review deleted
  • Resolution set to duplicate
  • Status changed from new to closed

Since get_template_part() only calls locate_template() and #13239 suggests adding a filter there, I'm closing this one as a duplicate.

#3 @SergeyBiryukov
7 years ago

  • Description modified (diff)
Note: See TracTickets for help on using tickets.