Want to load popup on homepage only using jQuery in wordpress

I am creating a popup plugin in WordPress. In my plugin, a popup opens on every page but I just want to show it on home page.

I know how to get it in PHP but don’t know hot to get the home url in jQuery.

Read More
setTimeout(function(){
    if($.cookie('SFPopup') == null){
        $('#sfp_Modal').modal('show');
    }else{          
        $('#sfp_Modal').modal('hide');
    }
}, 3000); 

This is how I am showing my popup using a cookie condition but I also want to show it only on home page not inner page.

This is my working code

<?php
function sf_display_popup(){
if (is_front_page() == true) {
?>
<script>
    jQuery(document).ready(function($) {
            $.cookieBar();
                setTimeout(function(){
                     //var site_url = '<?php echo home_url(); ?>';

                    if($.cookie('SFPopup') == null || $('body').hasClass('home')){
                        // alert(site_url);
                            $('#sfp_Modal').modal('show');
                        }else{          
                            $('#sfp_Modal').modal('hide');
                        }
                }, 3000); 

        });

</script>
<?php
    }
}
?>

Related posts

2 comments

  1. try with checking body for class home. If body have home class it is home page.

    if ($('body').hasClass('home')) { // show pop up }
    

Comments are closed.