If want to add a session for other pages but need to destroy that session on the front page. Then the code will be like this-
function my_session(){
// Instance of Requests_Session class
$request_session = new Requests_Session();
// Destroying the session if it is front page of the site and the session exists
if( is_front_page() && $request_session->__isset( 'test' ) ){
$request_session->__unset( 'test' );
}
// Adding the session if it is not front page of the site and the session not exists
if( !is_front_page() && !$request_session->__isset( 'test' ) ){
$request_session->__set( 'test', 'my test' );
echo $request_session->__get( 'test' );
}
}
add_action('template_redirect', 'my_session');
You must log in before being able to contribute a note or feedback.
If want to add a session for other pages but need to destroy that session on the front page. Then the code will be like this-