This was my solution to loading a popup on a specific query string using PHP. To accomplish this I used Magnific Popup for the popup / lightbox functionality so this snippet assumes you have that installed. However you can use this snippet with any jQuery lightbox plugin you want. Just make sure to update the snippet to match your specific needs.
So what I did was pull the query string into a variable $url then assigned another variable $correct_query_string with the string I needed to load the popup on page load. With these I just set a conditional to see if they matched and if so, I output the script to load that popup on pageload by using .click().
Once complete, a popup now loads conditionally if a user visits
http://www.website.com/?applyforscholarship
But not if they visit
http://www.website.com
<?php | |
function hjs_home_page_popup() { | |
if (is_front_page()) { | |
$url = $_SERVER['QUERY_STRING']; | |
$correct_query_string = 'applyforscholarship'; | |
if ($url == $correct_query_string) { ?> | |
<script type="text/javascript"> | |
jQuery(document).ready(function($) { | |
$('.open-popup-link').click(); | |
}); | |
</script> | |
<a href="#applyforscholarship" class="open-popup-link">Show inline popup</a> | |
<div id="applyforscholarship" class="white-popup mfp-hide"> | |
Your Content Here | |
</div> | |
<?php } | |
} | |
} | |
?> |
Leave a Reply