Question

We use this code to display the link ...

$mp3Link = wp_get_attachment_url($mp3_file_id);
<a class="w3-black" href="'.$mp3Link.'" rel="nofollow" >mp3</a>

It looks like this now :

https://example.com/wp-content/uploads/2020/12/Amir.mp3

I want it to be like this :

https://sub.example.com/wp-content/uploads/2020/12/Amir.mp3

I mean, I just want to do this by editing the above code

Was it helpful?

Solution

$mp3Link = wp_get_attachment_url($mp3_file_id);
$mp3Link = str_replace( 'example.com', 'sub.example.com', $mp3Link ); 
<a class="w3-black" href="'.$mp3Link.'" rel="nofollow" >mp3</a>

replace example.com with your actual domain - it's not the most elegant solution, but might work.

Licensed under: CC-BY-SA with attribution
Not affiliated with wordpress.stackexchange
scroll top