Skip to content

Instantly share code, notes, and snippets.

@joshcoxjcs
Created April 30, 2026 10:54
Show Gist options
  • Select an option

  • Save joshcoxjcs/799d4a3c39f110ea9722b737c93f82b0 to your computer and use it in GitHub Desktop.

Select an option

Save joshcoxjcs/799d4a3c39f110ea9722b737c93f82b0 to your computer and use it in GitHub Desktop.
Share WordPress draft posts for client review without a plugin - drop in functions.php
<?php
/**
* Shareable draft preview for WordPress.
*
* Add ?key=YOUR_KEY to any post URL to preview drafts, pending,
* and scheduled posts without logging in.
*
* Change the key value below to something unique and hard to guess.
*/
add_action('pre_get_posts', 'allow_draft_preview');
function allow_draft_preview($query) {
if (is_admin() || !$query->is_main_query() || !$query->is_singular()) {
return;
}
$key = isset($_GET['key']) ? sanitize_text_field(wp_unslash($_GET['key'])) : '';
if (hash_equals('guestViewer_dBJ8vfaY', $key)) {
$query->set('post_status', ['draft', 'pending', 'future']);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment