admin管理员组文章数量:1289601
is_front_page() in the below code is not working... this function just doesn't run when I'm on the front page, any idea why? am I doing something wrong?
function save_landing_page_slider()
{
if (isset($_GET['slider']) && is_front_page()) {
$current_user_id = get_current_user_id();
$slider = $_GET['slider'];
update_field('user_landing_slider', $slider, 'user_'.$current_user_id);
}
}
add_action('init', 'save_landing_page_slider', 10, 2);
is_front_page() in the below code is not working... this function just doesn't run when I'm on the front page, any idea why? am I doing something wrong?
function save_landing_page_slider()
{
if (isset($_GET['slider']) && is_front_page()) {
$current_user_id = get_current_user_id();
$slider = $_GET['slider'];
update_field('user_landing_slider', $slider, 'user_'.$current_user_id);
}
}
add_action('init', 'save_landing_page_slider', 10, 2);
Share
Improve this question
asked Jul 12, 2021 at 0:49
user205498user205498
31 bronze badge
0
1 Answer
Reset to default 1add_action('init', 'save_landing_page_slider', 10, 2);
init
is too early — if you look at the WordPress query overview on Codex, init
is (as of writing) the second step, whereas is_
variables like $is_page
(or WP_Query::$is_page
) that are used by conditional tags like is_front_page()
are only set in step 4, so instead of init
, you should use a later hook like wp
or template_redirect
:
add_action( 'template_redirect', 'save_landing_page_slider' );
So in order for conditional tags to work properly, make sure to call them in the right hook or place.
Additionally, you should also understand when would is_front_page()
return true, e.g. when your homepage is set to a static Page, and that you're on the homepage.
本文标签: isfrontpage is not working in my functionsphp
版权声明:本文标题:is_front_page is not working in my functions.php 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741449181a2379385.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论