change template with button
I created plugin with code :
function fxn($theme) {
if(isset($_POST['zmien'])){
$theme = 'loose';}
else{
$theme = 'twentytwenty';}
return $theme;
}
add_filter('template', 'fxn');
add_filter('option_template', 'fxn');
add_filter('option_stylesheet', 'fxn');
I found the code and adapted it to my website. I have created the plugin and it works only partially. When I click the button the template changes but when I click on any element on the new template the page returns to the previous template.
How can I make a change of template active until the end of browsing the page?