WordPress.org

Make WordPress Core

Opened 4 years ago

Closed 4 years ago

Last modified 3 years ago

#40258 closed enhancement (duplicate)

Add hook for get_template_part

Reported by: 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
4 years ago

Another problem arises when in theme there is:

get_template_part( 'components/footer/site');

as we cant add action like this:

add_action('get_template_part_{$slug}'
which should be:
add_action('get_template_part_components/footer/site'

however, that action contains slash and cant be added.

Version 0, edited 4 years ago by tazotodua (next)

#2 @swissspidy
4 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
3 years ago

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