Tag Info

Hot answers tagged

1

You can just look at url, load the file and exit. That can be done when WordPress loaded its environment, e.g. on 'init'. add_action('init', function() { $url_path = trim(parse_url(add_query_arg(array()), PHP_URL_PATH), '/'); if ( $url_path === 'retail' ) { // load the file if exists $load = locate_template('template-retail.php', true); ...


1

One way to retrieve the name of the template as defined in the file could be like this: function get_template_name () { // List all available template names for current theme $available_templates = wp_get_theme()->get_page_templates(); // Get filename of page template we are on $template_filename = basename(get_page_template()) // ...


1

An alternative to @Ben Cole that's less intensive (especially if you have several page templates), but not as awesome because it doesn't use the WP_Theme object ;) function wpse_184317_get_template_name( $page_id = null ) { if ( ! $template = get_page_template_slug( $page_id ) ) return; if ( ! $file = locate_template( $template ) ) ...



Only top voted, non community-wiki answers of a minimum length are eligible