Skip to content

Instantly share code, notes, and snippets.

@aldomatic
Created July 31, 2019 17:50
Show Gist options
  • Save aldomatic/c5a783ab07e84cb9a2cd87a8b3b097eb to your computer and use it in GitHub Desktop.
Save aldomatic/c5a783ab07e84cb9a2cd87a8b3b097eb to your computer and use it in GitHub Desktop.
Update the default preview link
<?php
add_filter('preview_post_link', array( $this, 'wp_gatsby_preview_setup_preview_link' ));
public function wp_gatsby_preview_setup_preview_link() {
$site_url = 'https://mygatsbysite.com';
$id = get_the_ID();
$post = get_post($id);
$slug = $post->post_name;
$post_status = $post->post_status;
$nonce = wp_create_nonce( 'wp_rest' );
$pt = get_post_type_object(get_post_type());
$post_type = str_replace('_', '-', get_post_type($id));
$link = $site_url.'/blog/'.$slug.'?id='.$id. '&_wpnonce='.$nonce.'&preview=true';
return $link;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment