Created
July 31, 2019 17:50
-
-
Save aldomatic/c5a783ab07e84cb9a2cd87a8b3b097eb to your computer and use it in GitHub Desktop.
Update the default preview link
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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