2

I am currently using a headless WordPress with NextJS and making adjustments in custom plugin index.php file.

Within the admin, I am trying to create a better user experience for our content writers and I was able to get the post_row_actions hook to work in swapping out the the main domain...

I was also able to get the icon at the top to view the post with the new domain; however, I am unable to get the actual URL link when you click on it to use the new domain name....

The first screenshot is a popup if you click on the URL on the sidebar and that does not work.

this DOES NOT WORK

this works

The following code is used to adjust the top two screenshots:

function my_custom_sample_permalink($permalink) {
  $new_permalink = str_replace(home_url(), 'https://preview.domain.com', $permalink);

  // Return the modified permalink.
  return $new_permalink;
}

add_filter('get_sample_permalink', 'my_custom_sample_permalink', 10, 1);

The problem that I am having is that the link outlined in the screenshot by black marker is NOT going to the preview.domain.com page, but is showing the correct domain on the link.

1 Answer 1

1

You can use the post_link filter to do this.

Example:

function modify_post_link( $url, $post, $leavename=false ) {
  if ( $post->post_type == 'post' ) {
    $url = str_replace(home_url(), 'https://preview.domain.com', $url);
  }
  
  return $url;
}
add_filter( 'post_link', 'modify_post_link', 10, 3 );

In fact, with this you don't even need your previous filter for get_sample_permalink.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.