最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

attachments - Add a word to the firstwp_get_attachment_urlas the subdomain name

programmeradmin0浏览0评论

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
Add a comment  | 

1 Answer 1

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.

发布评论

评论列表(0)

  1. 暂无评论