Custom preview_post_link not working for draft post

Question

I am trying to change the functionality of the preview button so the URL can be changed to the address I want. I am using the code below

function preview_link_fix( $preview_link ){

    $mydomain = 'http://localhost:3001/preview';
    $post = get_post( get_the_ID() );

    $args = array(
        'post'    => $post,
        'preview' => 'true'
    );
    return add_query_arg( $args, $mydomain );
}

This basically takes the preview to my react front end page. This is working fine for the custom post types and the post only in the case if they are published and the posts which are in the draft the button is not working but the preview option which is below the post in the post-list is working.

So the preview option which is shown in the image is working but for the preview button inside the edit, post page is not working. Please anybody can help me with which this problem.
enter image description here

--------------------------------------------------

>>> Share a link to this question, just copy and paste the code bellow on your web page <<<

<a href="https://www.wptricks.com/question/custom-preview_post_link-not-working-for-draft-post/">

Custom preview_post_link not working for draft post</a>
0
, , Mohit Nihalani 1 month 0 Answers 52 views 0

Leave an answer