0

This code:

$files[$file->ID]['file_title'] = '<p><a target="_blank" href="' . esc_url( wp_get_attachment_url( $file->ID ) ) . '">' . $real_title . '</a>' . $title . '</p>';

Gives me:

https://example.com/wp-content/uploads/2022/03/sample.pdf`

But I want:

/wp-content/uploads/2022/03/sample.pdf`

How do I remove https://example.com/?

user3783243
  • 5,368
  • 5
  • 22
  • 41

1 Answers1

1

You can use parse_url to get the path information from a URL:

parse_url(wp_get_attachment_url($file->ID) , PHP_URL_PATH)

https://3v4l.org/5KmsJ

Alternatively str_replace or preg_replace could be used to remove https://example.com/ that those can result in incorrect results.

user3783243
  • 5,368
  • 5
  • 22
  • 41