Your functions.php
doesn’t create output, so you should use locate_template()
.
Example:
locate_template( 'php/functions.nav-menu.php', TRUE, TRUE );
You’ll find this function in wp-includes/theme.php
. The first parameter is the file path relative to the theme root, the second tells WordPress to load it (or not), and the third to load it just once.
Now a child theme can override the file by just placing a file with the same name to the same place in its own theme root.
Related Posts:
- Using require_once for parent-directory not working but is working in sub-directories
- get_template_part vs action hooks in themes
- The proper way to include/require PHP files in WordPress
- What is the right way to include a wp-admin file in your theme?
- How can I see what template parts are being called for rendering the viewable page?
- Single Page WordPress Theme – Using page templates
- Finding Page Template and Displaying Content
- Some doubts about how to show posts in a custom theme?
- Should I use include or load_template for including shortcodes, plugins and so on?
- What is the best way to organize template parts?
- Is it possible to include an HTML flat-file website inside a WordPress theme?
- get_template_part() doesn’t work
- How do I get standard posts to open up in their own template when using get_template_part()?
- Is there a way to retrieve the calling template part?
- Is it possible to have a Theme with built-in physical page files?
- Exclude function from homepage only?
- How can I include custom Gutenberg Blocks in a theme?
- Incorrect search results in search.php – issue triggered by using `define(‘BodyID’, ‘search’); the_post();` in search.php
- Want to include ad code after related post
- WordPress Includes mejs 404 error
- Menu items description? Custom Walker for wp_nav_menu()
- How to define and link full path to css located at a random folder on header.php
- Sizing screenshot.png without losing aspect ratio
- Software for WordPress Theme and Plugin Development? [closed]
- When to use is_home() vs is_front_page()?
- What is the preferred way to add custom javascript files to the site?
- Passing variables through locate_template
- Get the blog page URL set in Options
- How to create .pot files with POedit?
- How do I get the theme URL in PHP?
- Why when I submit a form in wordpress it loads a 404 page though URL is correct
- What is the constant WP_USE_THEMES for?
- Worthwhile to restrict direct access of theme files?
- How Do I Protect My Premium WordPress App Theme from Copying?
- How to detect mobile devices and present them a specific theme?
- Using wp_add_inline_style without a stylesheet
- Is there any way to use get_template_part() with folders?
- How to add posts to custom menus?
- WordPress Theme Preview Image
- How To extend WP_Customize_Control
- What is the difference between front-page.php and home.php? [duplicate]
- How can I get page slug
- Does the functions.php file ever get called during an AJAX call? Debug AJAX
- When to use _e and __ for the translation?
- What is a Theme textdomain?
- How to show a custom meta box on the “Quick Edit” screen?
- How to add CSS class to custom logo?
- How to add custom css file in theme?
- How important is it to enqueue a theme’s stylesheet?
- CSS not updating in browser when I change it
- Display Search Result Count
- wp_nav_menu(), how to change class?
- theme path in javascript file
- Is wp_is_mobile() effective?
- Display Menu Name using wp_nav_menu
- Making update notification functionality for my themes
- What questions do you ask when asked to give an estimate on theme development?
- How to remove dashicons.min.css from frontend?
- How do I remove a pre-existing customizer setting?
- Minimum Template Files for Theme Development
- What’s the difference between home.php and index.php?
- pass object/JSON to wp_localize_script
- Theme Activate Hook
- Solutions for generating dynamic javascript / CSS
- wp_redirect() – headers already sent
- Can I create my own “Recent Posts” widget or customize the existing one?
- Custom single template for a specific category
- how can I add an icon/image for a child theme?
- How can I add a URL field to the attachments window?
- The the_post_thumbnail without srcset?
- Get the first image from post content (eg.: hotlinked images)
- after_setup_theme always runs
- When to use add_action(‘init’) vs add_action(‘wp_enqueue_scripts’)
- Getting failure when using filemtime() with wp_enqueue_style
- Do I actually need to link my theme’s style.css in the theme files
- Why is wp_head() creating a top margin at the top of my theme header?
- How to store widget fields data as an array?
- How do I add version control to my workflow?
- Using classes instead of global functions in functions.php
- WordPress API Menu/Submenu Order
- How can I display a menu on certain pages only?
- Enqueue a stylesheet for login page and make it appear in head element
- Adding a div to wrap widget content after the widget title
- How to insert a logo in the header?
- How to set permalink structure via functions.php
- What is $post_id? is it a global variable in WordPress?
- How to override pluggable function in theme?
- How to move page template files like page-{slug}.php to a sub-directory?
- WooCommerce shop page to use my custom template [closed]
- Theme customizer – settings order
- What is the difference between wp_register_sidebar_widget and register_widget?
- Reset positions of metaboxes in admin
- CSS classes for theme
- “Quick Edit” > update clears out my custom meta values
- How to enqueue script if widget is displayed on page?
- Custom Image section in Customizer
- A way to automatically install pages on theme install?
- Get entered value of customiser field for live preview
- Add custom classes to anchor in wp_nav_menu
- How to remove search bar from a wordpress theme? [closed]