Skip to content

Instantly share code, notes, and snippets.

@mikemanger
Created March 19, 2014 18:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mikemanger/9648571 to your computer and use it in GitHub Desktop.
Save mikemanger/9648571 to your computer and use it in GitHub Desktop.
Sessions in WordPress themes & plugins.
/**
* Setup last page context.
*/
session_start();
function my_theme_php_shutdown() {
$_SESSION['my_theme_from_search'] = is_search();
}
add_action( 'shutdown', 'my_theme_php_shutdown' );
/**
* Display helper navigation to go back to search results/home when applicable.
*
* @return void
*/
function my_theme_helper_nav() {
if ( isset($_SESSION['my_theme_from_search']) && $_SESSION['my_theme_from_search'] && ! is_search() ) {
echo sprintf(__('<a href="%s">&laquo; Back to search results</a>', 'theme'), 'javascript:history.go(-1)' );
} else {
echo sprintf(__('<a href="%s">&laquo; Back to home</a>', 'theme'), esc_url( home_url( '/' ) ) );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment