Change WordPress’ media upload URL?

It was actually easier than I thought.

function route_uploads_past_cdn( $url, $path ) {
    $upload_paths = array( 'async-upload.php', 'media-new.php' );
    if( !in_array( $path, $upload_paths ) ) {
        return $url;
    }

    return str_replace('www.', '', $url);
}
add_filter( 'admin_url', 'pew_route_uploads_past_cdn', 10, 2 );

The URL for uploading media would normally be http://www.example.com/wp-admin/media-new.php would now be http://example.com/wp-admin/media-new.php since the URLs are passed through admin_url() which you can filter.

Leave a Comment

error code: 523