• Hey there, I’m trying to configure a CDN, however when I include directories (e.g. wp-uploads) the url’s are re-written from:

    mywebsite/wp-uploads/my-file.jpg

    to:

    cdn.mycdnname.com/wp-uploads/my-file.jpg

    However my CDN does not include the subfolder, it hosts the files as follows:

    cdn.mycdnname.com/my-file.jpg

    I can see from the code that WPSC essentially just swaps out the Site URL with Off-site URL.

    Does anyone have any suggestions on how I might be able to gracefully rewrite these without modifying the core plugin code?

    Many thanks!

    • This topic was modified 4 years, 2 months ago by mingis.
Viewing 2 replies - 1 through 2 (of 2 total)
  • You could add your own filter on the “wp_cache_ob_callback_filter” filter with a priority greater than 10 so it runs after the CDN code translates your images.

    add_filter( 'wp_cache_ob_callback_filter', 'fix_my_cdn_urls' );

    That filter works on the cached page so you can change any text before it’s stored on disk.
    Then create a function called fix_my_cdn_urls that removes the wp-uploads directory for those CDN urls.

    Thread Starter mingis

    (@mingis)

    Awesome idea, thanks Donncha!

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘CDN Url replacement’ is closed to new replies.