WP SITES

3095 Coded Tutorials & 297 Plugins

How To Use A Page Template Anywhere In WordPress Using Template Include

Using the template_include function included in WordPress, paste this code in your child themes functions.php file and modify accordingly.

add_filter( 'template_include', 'front_page_landing_template', 99 );

function front_page_landing_template( $template ) {

if ( is_front_page()  ) {
$new_template = locate_template( array( 'page_landing.php' ) );
if ( '' != $new_template ) {
return $new_template ;
        }
    }

return $template;
}

The function only works with page templates and doesn’t work for archive or other template files.

Using Custom Post Type Archives Anywhere

Was this helpful?

Yes
No
Thanks for your feedback!

One response to “How To Use A Page Template Anywhere In WordPress Using Template Include”

  1. Using Different Custom Single Post Templates

    […] Use Any Template Anywhere in Your WordPress Theme […]

Leave a Reply