我总是把它挂在template_redirect
. 类似这样:
add_action( \'template_redirect\', \'custom_check_for_redirect\' );
function custom_check_for_redirect(){
global $wp_query; # It could work without this too!
if( is_page( 8219 ) )
$days_to_expire = 30;
if (!is_admin() && !isset($_COOKIE[\'already_visited\'])) {
setcookie(\'already_visited\', true, time() + 86400 * $days_to_expire);
wp_redirect(home_url(\'/welkom\'), 302);
exit;
};
};