要做到这一点,你可以采取很多行动,我认为最好的一次行动是wp
或template_redirect
.
使用这些操作中的任何一个,代码如下所示,此代码进入functions.php
add_action(\'wp\', \'bt_update_user_homepage_meta\');
function bt_update_user_homepage_meta () {
// get user id, if user is not logged in then it will be 0
$user_id = get_current_user_id();
// now we check if we are in front page or not and we update the user meta accordingly
// if user is not logged in this code will try to update the meta for user 0,
// because this user doesn\'t exist, nothing will happen
if (is_front_page()) update_user_meta($user_id, \'pagehome\', \'1\');
else update_user_meta($user_id, \'pagehome\', \'0\');
}