wordpresscodex

File path without domain name from wp_get_attachment_url()


wp_get_attachment_url() process full file path like

http://example.com/wp-content/uploads/2014/12/aura.mp3

I want the url without http://example.com/ So, I want above example as wp-content/uploads/2014/12/aura.mp3 instead of http://example.com/wp-content/uploads/2014/12/aura.mp3. How to do it?


Solution

  • You can really easily explode it by / and then take the part with index 3. Example

    $url = wp_get_attachment_url(id); //id is file's id
    $urllocal = explode(site_url(), $url)[1]; //output local path