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

  • You can’t pass WP_Post object as query arg... – Krzysiek Dróżdż Feb 5 '19 at 8:49
  • @KrzysiekDróżdż but it is working if I pass the post_object, the only place it is not working in the post edit page, it is even working with the preview option showed in the image. – Mohit Nihalani Feb 5 '19 at 8:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.