I prefer hooks, since they are more flexible: you can hook into them from your theme’s functions.php
file, but also from plugins. I try to put as much logic in plugins, so that the themes contain mostly layout stuff.
If you use an action hook, it is still possible to use get_template_part()
in that hook handler. This gives you the best of both worlds. You could probably even create a default hook that calls get_template_part()
, so that people who don’t have much experience with coding can add extra files, and others can remove this hook if they don’t want to.
Regarding performance: get_template_part()
uses (in locate_template()
) file_exists()
one, two or four times (depending on how you call it). It appears file_exists()
is very fast, and uses caching in PHP and maybe even in the OS. So that is probably not an issue.
Related Posts:
- after_setup_theme always runs
- Add custom classes to anchor in wp_nav_menu
- Getting instance variable in scope of ‘wp_enqueue_scripts’
- Display a different theme for not logged-in users
- What can I hook into after_setup_theme?
- Single Page WordPress Theme – Using page templates
- How do I “unhook” / de-register jQuery so that it’s not called as part of wp_footer();?
- Finding Page Template and Displaying Content
- Some doubts about how to show posts in a custom theme?
- How to add theme support?
- Theme Development: Starter Content after hook
- Never actually adding the action? Or do I have to call the action?
- Add content after get_header
- How to make a function occurs for one time?
- Is there any filter or action hook to remove layout classes from appearing in my templates?
- Add text when displying attribute with a hook on single product page
- Sizing screenshot.png without losing aspect ratio
- How to add CSS class to custom logo?
- How to add custom css file in theme?
- theme path in javascript file
- Theme Activate Hook
- The the_post_thumbnail without srcset?
- The proper way to include/require PHP files in WordPress
- When to use add_action(‘init’) vs add_action(‘wp_enqueue_scripts’)
- Do I actually need to link my theme’s style.css in the theme files
- Using classes instead of global functions in functions.php
- WordPress API Menu/Submenu Order
- How to insert a logo in the header?
- How to move page template files like page-{slug}.php to a sub-directory?
- Should we use get_template_part() in functions files instead of include_once?
- CSS classes for theme
- How to remove search bar from a wordpress theme? [closed]
- Should `get_template_directory_uri()` be escaped?
- Get url of thumbnail from the media uploader
- My child theme doesn’t work Error: “The parent theme is missing. Please install your parent theme”
- How to remove the Theme Customization Button from the dashboard and themes options page?
- How To Add New Option Types To Option Tree?
- WP 3.4 – what action/hook is called when theme customisation is saved?
- What WP folder can I use to write files to?
- Are the WordPress Core CSS styles really all nessesary?
- Add a dropdown to theme customizer
- Should I use set_transient or update_option?
- Why doesn’t default WordPress page view use force_balance_tags?
- Page template in two level deep folder
- Theme Customizer : how to create multiple-level panel
- Why I can’t add a CSS style in this WordPress theme?
- Theme file for all pages that are a child of a specific page
- Allow Shortcode in Theme Customizer
- Where to post/upload the new theme for WordPress theme repository
- Setting multiple default background images?
- Template for individual post designs
- How to make a theme with more than one CSS file?
- Is it good to rename theme folder downloaded from WordPress.org?
- Best practice way to implement custom sections into a WordPress theme
- Editing the custom background CSS
- What is the problem if I use CDN in my WordPress parent theme(built using bootstrap)?
- register_sidebar ignores ‘id’ and ‘class’
- Check php version before theme activation
- What, specifically, should be included in theme_name_setup()?
- How to get gallery images?
- Is it possible to use line break in theme description?
- Is the theme customizer slowing down my site?
- How can I get wp_head() as a string instead of echoing it?
- What’s the earliest point I can get the queried object ID?
- How do I Make a Theme “plugin-ready”?
- Best practice (forward compatibility) for theme options
- Automatic Updates For Private And Commercial Themes?
- What is a good way to pass a variable from add_action to a Theme?
- Add colors to existing color palette without replacing it
- Child Theme not loading parent CSS
- Where do I find the functions triggered within a hook?
- What does “Do not deregister the jquery script in the administration area” mean?
- How can I remove “Proudly powered by WordPress” from twentyeleven without modifying footer.php?
- What is the best book to learn how to make themes for wordpress?
- Grab the first paragraph of each post
- How to access certain WP functions inside custom class, in theme folder
- How can I see what template parts are being called for rendering the viewable page?
- add_image_size is scaling, even though crop is set to true
- Use of undefined constant FS_CHMOD_DIR – assumed ‘FS_CHMOD_DIR’
- Identifying the priority of style.css so I can make a small CSS file load last
- How to show next Post Thumbnail image in WordPress using current post id
- Theme elements not translating
- Symlink a directory to wp-content/themes
- Pushing updates to your premium theme
- Registering Sidebars and Sidebar Widgets. Sidebar Widgets Not Displaying
- Where can I find a good reviewed collection of Twenty Ten child themes?
- What’s the difference between hooks, filters and actions? [duplicate]
- How to check if post has any tag?
- How to use filter hook ‘post_updated_messages’ in coherence with action hook ‘save_post’
- Get password when user registers and save it sha1 into database
- What are WooCommerce starter themes? [closed]
- How do I get gallery thumbnail URL and change the default thumbnail size?
- Front End Post Submit Form
- How do I get a parent theme modification from a child theme?
- Removing the default sidebar from admin panel
- How do I remove RSS feeds from themes?
- Select menu on browser resize
- How to disable the gradient and font size internal CSS added by WordPress when using theme.json
- Passing variable in hooks and filter
- add_theme_support( ‘custom-header’ ) does not add option menu in dashboard