In my case I have created a page named test.php
inside my theme folder. I have a specific html structure in test.php
file. I don't include header and footer files here. I hard code them in this file because they are different.I validate user details using $_SESSION
in function.php
. Now what I want to do is, I want to validate the SESSION
. If the SESSION is false I need to load the test.php
file, else I will follow Wordpress flow.
You mentioned:
I validate user details using $_SESSION in function.php
So I'm assuming you have the validation part down, and are struggling with the redirection to test.php
. You can achieve the redirect by hooking in to the template_redirect
action.
Inside your functions.php
, add:
add_action( 'template_redirect', function() {
if (!session_is_validated()) {
include( get_template_directory() . '/test.php' );
exit;
}
});