Created
March 19, 2014 18:48
-
-
Save mikemanger/9648571 to your computer and use it in GitHub Desktop.
Sessions in WordPress themes & plugins.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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">« Back to search results</a>', 'theme'), 'javascript:history.go(-1)' ); | |
} else { | |
echo sprintf(__('<a href="%s">« 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