PHP sessions in wordpress

Add this to you functions.php

add_action('init', 'myStartSession', 1); //Initialize session
add_action('wp_logout', 'myEndSession'); //End session on logout
add_action('wp_login', 'myEndSession'); //End session on account change

function myStartSession() {
   if(!session_id()) {
      session_start();
   }
}

function myEndSession() {
   session_destroy ();
}

Access the value in normal PHP fashion

$_SESSION['myKey'] = "Some data I need later";

Source: https://silvermapleweb.com/using-the-php-session-in-wordpress/

WordPress Custom Page Template

To create a custom page template make a new file starting with a Template Name inside a PHP comment. Here’s the syntax:

<?php
/*
Template Name: My Custom Page
*/

Once you upload the file to your Theme’s folder, the template name, “My Custom Page”, will list in the Edit Page screen’s Template dropdown. (The select list has a maximum width of 250px, so longer names may be cut off.)

A custom page template file can be in a sub-folder, or, if using a Child Theme, in its Parent Theme’s folder.

Back to Top