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?
You can really easily explode it by / and then take the part with index 3. Example
Here is the WordPress way using WordPress functions (avoid hacking):
WordPress has tons of functions, so first try to find the function on the docs: https://developer.wordpress.org/reference/functions/get_attached_file/
You can use PHP’s function
explode
.Here is the code:
You can
implode
your entire url on/
andarray_slice
from the end, then implode it back in on/
.That way if your WordPress is on a subdomain or localhost or the images are on S3 it won’t crash.