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 :
.mp3
I want it to be like this :
.mp3
I mean, I just want to do this by editing the above code
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/wp-content/uploads/2020/12/Amir.mp3
I want it to be like this :
https://sub.example/wp-content/uploads/2020/12/Amir.mp3
I mean, I just want to do this by editing the above code
Share Improve this question edited Dec 22, 2020 at 7:03 fuxia♦ 107k38 gold badges255 silver badges459 bronze badges asked Dec 21, 2020 at 12:50 sa eusa eu 33 bronze badges 3- Do you mean that the second URL works and you just want a way to edit the first string so that is matches? - You could do something like $string = str_replace( 'domain', 'sub.domain', $string); – Q Studio Commented Dec 21, 2020 at 12:55
- Or check out this filter - developer.wordpress/reference/hooks/wp_get_attachment_url – Q Studio Commented Dec 21, 2020 at 12:58
- I do not know how to please embed in my code – sa eu Commented Dec 21, 2020 at 13:16
1 Answer
Reset to default 0$mp3Link = wp_get_attachment_url($mp3_file_id);
$mp3Link = str_replace( 'example', 'sub.example', $mp3Link );
<a class="w3-black" href="'.$mp3Link.'" rel="nofollow" >mp3</a>
replace example
with your actual domain - it's not the most elegant solution, but might work.