I am using a WP – Alert plugin for a wordpress website. The issue is that it displays on all the pages even though it is set as display on home page only. (is_home). However, my home page is a static home page so I have set it to is_front_page and still it displays on all the pages. If you could just let me know if I am missing out anything??
function wp_alert_add_sticky_alert(){
if(get_option('alert_show_on_site') == 'yes'){
$display = true;
$homeOption = get_option('alert_show_on_home');
$pageOption = get_option('alert_show_on_page');
$postOption = get_option('alert_show_on_post');
$getID = get_the_ID();
if($homeOption == 'yes' && is_home ()){
$display = true ;
}elseif($pageOption == 'yes' && is_page()){
$display = true ;
}elseif($postOption == 'yes' && is_single()){
$display = true ;
}else{
$display = false ;
}
if($display){
?>
<div class="sticky-box">
<div class="sticky-inner"><?php echo stripslashes(get_option('wp_alert_message')); ?>
</div>
</div>
<?php
}
}
}
?>
I added this line to the code above and still it won’t display on the static home page only.
} elseif($homeOption == ‘yes’ && is_front_page()){
$display = true ; }
Thanks in advance guys 🙂
WordPress loads
functions.php
before the$wp_query
object has been set up with the current page.is_front_page
is a wrapper around around$wp_query->is_front_page()
, and if the query hasn’t been set up, it’s always going to return false.For more on the topic, see this question : https://wordpress.stackexchange.com/questions/41805/is-front-page-only-works-in-theme-file-and-does-not-work-in-functions-php
To use it in your
functions.php
, you will have to wrap it in an action that is after the $wp_query object is instantiated.Is this showing in your static home page now??
Try this
Hope this works for you