Skip to content

Instantly share code, notes, and snippets.

@rawcreative
Created November 2, 2015 23:13
Show Gist options
  • Save rawcreative/432b5eb11d7779b32d99 to your computer and use it in GitHub Desktop.
Save rawcreative/432b5eb11d7779b32d99 to your computer and use it in GitHub Desktop.
WordPress relative-to-absolute attachments.
<?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