markfjb
Forum Replies Created
-
Forum: Developing with WordPress
In reply to: Retrieving filtered template nameMany thanks for the responses. I just realize that I probably should have been a bit more specific regarding my use case.
I am working on a website that is mostly only accessible once the user has logged in. There are however a few pages that are also visible when the user is not logged in. For a subset of these I would like to use the default template when the user is logged in, but a different one when the user is not logged in. Thus the previously mentioned code or rather the conditional statement would be more specific, like:
add_filter( 'template_include', 'special_page_template', 99 ); function special_page_template( $template ) { if ( is_page( 'test' ) && !is_user_logged_in() ) { $new_template = locate_template( 'special-page.php' ); return $new_template ; } return $template; }In this case just changing the template in Admin or creating a specific page template that will be used according to the template hierarchy won’t work.
I am working in a child theme and this function is in functions.php. I certainly can move this into a plugin, if this is the better place for such a function.
However I still have the problem that
is_page_template('special-page.php')doesn’t know about the switched template. I was wondering if there is a special function in WordPress to retrieve the template name that is actually in use, after all possible filtering has been applied.Hope this makes it more clear. Again sorry for not providing the full context from the start and apparently missing some essential details.