I'm getting most of what's going on in the following code, with some help from http://www.php.net and http://codex.wordpress.org/Function_Reference/.

In its current situation, only one page on the site triggers the popup form if no cookie is set. Is that functionality specified within this code?

Here's the functions:

if (isset($_POST['confirm']) && isset($_POST['location'])) { 
    setcookie("Location", $_POST['location'], time()+3600);     
elseif (!isset($_COOKIE["Location"])) {
    setcookie("Location", "", 1);
elseif (isset($_POST['deny'])) {
    setcookie("Location", "", 1);

// Popup confirmation 
function show_popup($content) {
    global $post;
    $location = get_post_meta($post->ID, 'location', TRUE);
    if (strtolower($l) == strtolower($location) || strlen($location) == 0   
    || (isset($_COOKIE["Location"]) && strtolower($_COOKIE["Location"])  
    == strtolower($location))) {
        return $content;
    } else {
        <div id="popup">
    <form action="<?php echo $PHP_SELF ?>" method="post">
    <input type="hidden" name="location" value="<?php echo $location; ?>" />
    <input type="submit" name="confirm" value="Yes" />
    <input type="submit" name="deny" value="No" />
add_filter('the_content', 'show_popup');

// Adds content to the <head> tag
function add_meta_content() {
if(isset($_POST['deny'])) {
<meta http-equiv="refresh" content="0;url=<?php bloginfo ('wpurl') ?>">
if(isset($_POST['confirm'])) {
<meta http-equiv="refresh" content="0;url=<?php echo $PHP_SELF; ?>">

add_action('wp_head', 'add_meta_content');
  • You should avoid using $PHP_SELF, in the above code you will get the same effect by not specifying an action at all, or by specifying an empty acction on your form element
    – Tom J Nowell
    May 6 '16 at 15:00

make sure that the post as a customfield named 'location' and the page you are viewing is using the_content() or if you want this to work on categories and archives then add:

add_filter('the_excerpt', 'show_popup');

hope this helps

  • glad i could help
    – Bainternet
    Feb 25 '11 at 22:48
  • @dooley don't forget you can mark this as the correct answer :)
    – Tom J Nowell
    May 6 '16 at 15:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.