Created
November 2, 2015 23:13
-
-
Save rawcreative/432b5eb11d7779b32d99 to your computer and use it in GitHub Desktop.
WordPress relative-to-absolute attachments.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function get_absolute_attachment_url( $image_id ) { | |
$url = wp_get_attachment_url( $image_id ); | |
$site_url = site_url(); | |
if(strpos($url, $site_url) === false) { | |
$url = trailingslashit($site_url) . $url; | |
} | |
// or | |
// | |
//if(strpos($url, $site_url) === false) { | |
// $url = site_url($url); | |
//} | |
return $url | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment