• Resolved slr1979

    (@slr1979)


    Hello

    I have written a function that delivers background images using jquery. The images are called by functions like get_background_image() etc. but obviously the URLs are not rewritten by CDN Enabler as they never pass through the plugin.

    Is there any way to access the CDN Enabler rewrite url function in my custom function to rewrite my image URLs before sending them to my jquery script? I am trying to avoid duplicate URLs in Page Speed.

    Many thanks for any advice.

Viewing 4 replies - 1 through 4 (of 4 total)
  • Unfortunately, that is a bit outside the scope of support we’re able to provide for CDN Enabler as custom setups can sometimes get tricky.

    However, if you have any other questions related to the built-in functionality of this plugin feel free to ask!

    pasada

    (@pasadamedia)

    @slr1979 You might consider str_replace to modify the image URL before sending to your script:

    $cdnurl = str_replace( '//www.', '//cdn.', $originurl );

    This example simply replaces https://www.anysite.com with cdn.anysite.com. You can use preg_replace for more complex replacements, but be aware that it has higher performance overhead.

    Hope this helps.

    Thread Starter slr1979

    (@slr1979)

    @pasadamedia

    Brilliant! With a few tweaks to my function, your solution worked perfectly. There was no need to used preg_replace as my url is just a subdomain of my top level domain.

    I very much appreciate your help today.

    pasada

    (@pasadamedia)

    @slr1979

    Glad everything worked out.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Rewrite URLS in my custom function?’ is closed to new replies.