Retrieving filtered template name
-
Hi,
I am currently modifying an existing theme. I’d like to dynamically adjust the page template based on certain conditions. I am doing this by adding a filter for ‘template_include’ and this is working fine, meaning the original template setting for a specific page gets overwritten and it then uses “special-page.php” instead of the default “page.php”:
add_filter( 'template_include', 'special_page_template', 99 ); function special_page_template( $template ) { if ( is_page( 'test' ) ) { $new_template = locate_template( 'special-page.php' ); return $new_template ; } return $template; }
However I have run into the problem that both templates use a common header, which has certain conditional outputs based on the call
is_page_template('special-page.php')
in it. Even though I have switched the template (by adding the filter) to “special-page.php”, the is_page_template() call isn’t recognizing this change and is apparently still picking up “page.php” from the database instead. What call would be the appropriate call instead to get the name of the actual template currently in use?
- The topic ‘Retrieving filtered template name’ is closed to new replies.