[wp-trac] [WordPress Trac] #51691: Call get_template_directory() once instead of multiple times for loading theme's files (performance boost)

WordPress Trac noreply at wordpress.org
Sun Nov 1 18:57:22 UTC 2020


#51691: Call get_template_directory() once instead of multiple times for loading
theme's files (performance boost)
----------------------------+------------------------------
 Reporter:  hellofromTonya  |       Owner:  (none)
     Type:  task (blessed)  |      Status:  new
 Priority:  normal          |   Milestone:  Awaiting Review
Component:  Bundled Theme   |     Version:  trunk
 Severity:  normal          |  Resolution:
 Keywords:                  |     Focuses:  performance
----------------------------+------------------------------

Comment (by joyously):

 I have reviewed themes in which they use a constant or theme function to
 do this, but it goes against the guidelines, which say to use core
 functions if they exist. The reason is that those filters are run!
 I once wrote a child theme for a theme that loaded a file in the setup
 function. I wanted everything except that file, so I filtered
 `get_template_directory` and loaded the child version instead of the
 parent version. If that theme had used a theme function that cached it
 instead of a core function, I couldn't have filtered it and made it work.

 If any enhancements are done, it should happen in the `get_template_*`
 functions themselves, instead of having themes change to another function
 to be more performant (but less "the WordPress way").

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/51691#comment:1>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list