Make WordPress Core

Opened 7 months ago

Closed 7 months ago

Last modified 6 months ago

#60153 closed enhancement (duplicate)

Add filters to `get_template_part()`

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

Description

I'm building a custom componentized framework for developing WordPress themes within my company. These components will be installed as composer libraries, and I'd like to include them like so...

get_template_part("company-name", "package-name", $args);

This would then be intercepted by a filter, to look in /wp-content/themes/my-theme/vendor/company-name/package-name for template.php.

This seems like a relatively easy thing to achieve, but there are currently no filters provided in get_template_part(). I'd appreciate the ability to filter the final path, with read access to the input parameters.

I can of course achieve this by wrapping get_template_part() in a helper function like company_name_get_template_part(), but I'd prefer the more elegant approach of filtering the function directory.

Change History (3)

#1 follow-up: @SergeyBiryukov
7 months ago

  • Keywords changes-requested removed

Hi there, welcome back to WordPress Trac! Thanks for the ticket.

Since get_template_part() uses locate_template() internally, it seems that this would be covered by #13239.

Also related: #42855.

#2 in reply to: ↑ 1 @revxx14
7 months ago

  • Resolution set to duplicate
  • Status changed from new to closed

Replying to SergeyBiryukov:

Hi there, welcome back to WordPress Trac! Thanks for the ticket.

Since get_template_part() uses locate_template() internally, it seems that this would be covered by #13239.

Also related: #42855.

Aha, you're right, I'll track that instead, thanks!

#3 @swissspidy
6 months ago

  • Milestone Awaiting Review deleted
Note: See TracTickets for help on using tickets.