Skip to content

Instantly share code, notes, and snippets.

@pbrocks
Created December 1, 2016 03:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pbrocks/f4e80a94f7a98880502b82023639ae38 to your computer and use it in GitHub Desktop.
Save pbrocks/f4e80a94f7a98880502b82023639ae38 to your computer and use it in GitHub Desktop.
Add to local wp-config.php to grab images when overriding urls
function filter_image_url( $url ) {
global $wpdb;
$siteurl = $wpdb->get_row( $wpdb->prepare( "SELECT option_value FROM $wpdb->options WHERE option_name = %d LIMIT 1", "siteurl" ) );
// $siteurl = $wpdb->get_row( $wpdb->prepare( "SELECT option_value FROM $wpdb->options WHERE option_name = siteurl LIMIT 1" ) );
$siteurl = $siteurl->option_value . '/';
$url = str_replace( WP_SITEURL, $siteurl, $url );
return $url;
}
add_filter( 'wp_get_attachment_url', 'filter_image_url' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment