This needs to be addresed in the page that is popped up rather than the page that contains the link that causes the page to pop up.
I have created a plugin to add a “Close this Window” link to a page that has been popped up from alligator popup or alligator menu popup:
<?php
/*
Plugin Name: Alligator Popup Close Button
Description: Shortcode to create a link to close a page popped up via alligator popup or alligator menu popup.
Author: Michael Atkins
Version: 1.0.0 beta
Author URI: https://cubecolour.co.uk/
License: GPLv3
Copyright 2015 cubecolour
Licenced under the GNU GPL:
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
// ==============================================
// Prevent Direct Access of this file
// ==============================================
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if this file is accessed directly
// ==============================================
// shortcode to add a 'Close this window' link
// usage: [closepopup]
// ==============================================
function cc_close_popup_shortcode( $atts, $content = null ) {
$closelink = '<script language="javascript">';
$closelink .= 'function CloseWindow() {';
$closelink .= 'window.close();';
$closelink .= '}';
$closelink .= '</script>';
$closelink .= '<a class="popup-close-button" href="javascript:CloseWindow()">Close This Window</a>';
echo $closelink;
}
add_shortcode( 'closepopup', 'cc_close_popup_shortcode' );
To use this, add a [closepopup]
shortcode where you want the link to appear on the page you have created as the popup.
This can be styled as a static button by adding some CSS rules to your child theme’s stylesheet – eg:
a.popup-close-button {
background: #444;
border: 1px solid #fff;
border-radius: 30px;
color: #fff;
display: block;
font-size: 16px;
line-height: 1;
padding: 10px;
position: fixed;
bottom: 20px;
right: 50%;
width: 200px;
margin-right: -100px;
text-align: center;
}
a.popup-close-button:hover,
a.popup-close-button:active {
background: #f660ab;
color: #fff;
}