Snippets: Using The wpex_template_parts Filter To Override Template Files

While Total includes many hooks and filters so you don't have to override most template files via a child theme if you do wish to do so you would normally copy and paste the template file to your child theme and edit it. For example if you wanted to edit header.php you would copy header.php to your child theme and modify it. We'll with the new 'wpex_template_parts' filter you can now create custom template files in your child theme to override the core files. For example you can make a header-home.php template file and easily override the default one. See example below:

/**
 * Example of 'wpex_template_parts' usage
 *
 * Important: The theme doesn't use wpex_template_parts for ALL partial template files, only the core files.
 *
 * @see    framework/core-functions.php
 * @return array
 */
function myprefix_override_header_template_part( $parts ) {

    // Replace the main header on the homepage with a header-home.php file in my child theme
    if ( is_front_page() ) {
        $parts['header'] = 'header-home';
    }

    // Return correct parts array
    return $parts;

}
add_filter( 'wpex_template_parts', 'myprefix_override_header_template_part' );

Version Required:3.4.1+

Snippet Type: PHP

All PHP snippets should be added via a child theme's functions.php file.