[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
Mon Nov 2 01:21:06 UTC 2020
#51691: Call get_template_directory() once instead of multiple times for loading
theme's files (performance boost)
----------------------------+------------------------------
Reporter: hellofromTonya | Owner: (none)
Type: enhancement | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Bundled Theme | Version: trunk
Severity: normal | Resolution:
Keywords: | Focuses: performance
----------------------------+------------------------------
Comment (by hellofromTonya):
Replying to [comment:6 apedog]:
> There's an assumption here - that {{{get_template_directory()}}} should
return the same value every time it's called by the theme. If so, the
result can be memoized and re-used. That's a big assumption for a default
theme that's meant to be extended in a child-theme by users.
That's true. You're right. It is an assumption.
That makes me wonder about the original design intent.
Is the design intent to allow each file to be loaded separately from
separate different directory sources? In other words, it's intentional to
allow the first file to be loaded from say the theme, 2nd file from the
child theme, 3rd from a plugin, etc.
{{{#!php
<?php
require get_template_directory() . '/classes/class-twenty-twenty-one-svg-
icons.php';
// Custom color classes.
require get_template_directory() . '/classes/class-twenty-twenty-one-
custom-colors.php';
new Twenty_Twenty_One_Custom_Colors();
// Enhance the theme by hooking into WordPress.
require get_template_directory() . '/inc/template-functions.php';
// Menu functions and filters.
require get_template_directory() . '/inc/menu-functions.php';
// Custom template tags for the theme.
require get_template_directory() . '/inc/template-tags.php';
// Customizer additions.
require get_template_directory() . '/classes/class-twenty-twenty-one-
customize.php';
new Twenty_Twenty_One_Customize();
// Block Patterns.
require get_template_directory() . '/inc/block-patterns.php';
// Block Styles.
require get_template_directory() . '/inc/block-styles.php';
}}}
Or is the design intent to filter the source directory where all of the
above files will be loaded from?
--
Ticket URL: <https://core.trac.wordpress.org/ticket/51691#comment:7>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list