Skip to content

Instantly share code, notes, and snippets.

@lewismcarey
Last active January 4, 2016 06:09
Show Gist options
  • Save lewismcarey/8579853 to your computer and use it in GitHub Desktop.
Save lewismcarey/8579853 to your computer and use it in GitHub Desktop.
Create WordPress preview whilst maintaining a holding page.
<?php
if ( !isset( $_SESSION ) ) // if no session
{
session_start(); // begin session
}
if ( $_SESSION['preview'] == "allow" || $_GET['preview'] == "allow" ) // if preview GET value exists (or preview SESSION)
{
if ( $_GET['preview'] == "allow" ) {
$_SESSION['preview'] = "allow"; // create the session - this means you only need to append '?preview=allow' once
}
if ( $_GET['preview'] == "end" ) { // if the user wishes to exit preview
unset($SESSION);
session_destroy();
}
/**
* Front to the WordPress application. This file doesn't do anything, but loads
* wp-blog-header.php which does and tells WordPress to load the theme.
*
* @package WordPress
*/
/**
* Tells WordPress to load the WordPress theme and output it.
*
* @var bool
*/
define('WP_USE_THEMES', true);
/** Loads the WordPress Environment and Template */
require( dirname( __FILE__ ) . '/wp-blog-header.php' );
} else {
// this is where your holding page goes
}
?>
# WORDPRESS Live Preview
This wrapper allows you to maintain a HTML holding page whislt seetting up a preview of a live WP site.
This is handy if you tend to work locally and don't intend to set up a remote test environment.
## Usage
http://www.yourwebsite.com?preview=allow
http://www.yourwebsite.com?preview=end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment