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


Comments

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

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

Leave a Reply

Join 5000+ Followers

Get The Latest Free & Premium Tutorials Delivered The Second They’re Published.