Add a word to the first // wp_get_attachment_url // as the subdomain name

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

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

$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.


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x