Skip to content

Instantly share code, notes, and snippets.

@bnecreative
Created September 30, 2020 20:16
Show Gist options
  • Save bnecreative/ab6d9829e03ee86cc4f3886035c8d9f2 to your computer and use it in GitHub Desktop.
Save bnecreative/ab6d9829e03ee86cc4f3886035c8d9f2 to your computer and use it in GitHub Desktop.
BNE Panels - Autoload a panel on a certain page once per day using a cookie.
<?php // Don't copy this line...
// Sets up a cookie to autoload a BNE Panel */
add_action( 'wp', function() {
$page_id = 890;
$panel_id = 940;
$expires = 86400; // 86400 = 1 day
// Check if a cookie exists
if( !isset( $_COOKIE['panel-autoload-page-'.$page_id] ) ) {
// Check if we're on the correct page
if( is_page( $page_id ) ) {
// Set the cookie!
setcookie( 'panel-autoload-page-'.$page_id, 'panel-'.$panel_id, time() + $expires, "/" );
// Open the Panel
add_action( 'wp_footer', function() use ($panel_id) {
?>
<script type="text/javascript">
jQuery(document).ready(function($) {
setTimeout(function() {
BNEPanelTrigger( 'open', <?php echo $panel_id; ?> )
}, 1000);
});
</script>
<?php
});
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment