有多种方法可以做到这一点,但我最近通过使用cookie解决了一个类似的问题。
add_action( \'init\', \'wpse_93797_cookie\' );
function wpse_93797_cookie() {
if ( !isset ( $_COOKIE[\'wpse_93797_cookie_name\'] ) ) {
// Do your stuff.
// Set your cookie so we don\'t do stuff the next time around.
// Note that 0 makes the cookie expire at the end of the user\'s browser session.
setcookie( \'wpse_93797_cookie_name\', \'some-value-we-did-stuff-btw\', 0, \'/\' );
}
}
Manual for cookies on PHP.net
也可能有帮助:
How can i set , get and destroy cookies in wordpress?