I am trying to trigger a popup within functions.php if certain conditions are met. The if else statement it self works perfectly, but I can't get the popup to open. I've tried calling a shortcode but that returns nothing.
I use a plugin (Popup Builder) for the popup itself. So the only thing I have access to is the unique class and the shortcode of the created popup. The plugin allows me to trigger the popup by onclick, by CSS, Hover, onload and exit intent. But none of those options are usefull when i trie to trigger it via shortcode directly from the functions.php file. As in, they don't work.
I could really use some directions here, becouse I feel I'm going nowhere. Below is the shortcode code I've tried. Ps: I know this can be done with javascript somehow, but since I don't have the id of the popup and my experience with JS are limited at best, I don't really know in which direction to turn. Hope someone can help me out!
function cookie_checker() {
// Check if cookie is already set
if(isset($_COOKIE['tln_cookie'])) {
// Do this if cookie is set
} else {
// Do this if the cookie doesn't exist
$shortcode = do_shortcode("[sg_popup id=1]");
return $shortcode;
}
}
add_action('init', 'cookie_checker');