Skip to content
  • Recent
  • Tags
  • Popular
  • Users
  • Search
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse

Lay Theme Forum

  1. Home
  2. General Discussion
  3. CDN integration

CDN integration

Scheduled Pinned Locked Moved General Discussion
10 Posts 3 Posters 371 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    michaelmaeder
    wrote on last edited by
    #1

    Hi all,

    I would like to use a CDN with Lay Theme. As some research has shown in the forum there does not seem to be an official way to integrate a CDN fully. Investigating the website after CDN activation shows me all JS, stylesheets and fonts load from the CDN, but the images do not load from there, but locally.

    I have identified two two sources for image urls, that would require to adopt the cdn path. Both are part of the wordpres REST API.

    This will rewrite the local domain path (mydomain.com') to the cdn domain (abcdef.stackpathcdn.com) for all calls of get_attachment_image_src. This will only be active after re saving the corresponding pages. Its added in the functions.php of my child theme:

    function filter_wp_get_attachment_image_src( $image, $attachment_id, $size, $icon ) {
        if(isset($image[0]))
        {
            $image[0] = str_replace(
                'mydomain.com',
                'abcdef.stackpathcdn.com',
                $image[0]);
        }
        return $image;
    };
    add_filter( 'wp_get_attachment_image_src', 'filter_wp_get_attachment_image_src', 99, 4 );
    

    Similarly Lay Theme seems to store a bunch of prepared JSON for Gridder in options fields. This JSON seems to deliver the image URLs relative (without protocol or domain). I was looking for a Wordpress filter to filter for any call to get_option for any option containing "_gridder_json" in their name, yet could not find a catch all filter for this. Does anyone have a tip on how to achieve this? WOuld be nice if I could also load the images from the CDN, which will improve page speed dramatically.

    Best, MM

    1 Reply Last reply
    0
    • mariusjopenM Offline
      mariusjopenM Offline
      mariusjopen
      Global Moderator
      wrote on last edited by
      #2

      Dear @michaelmaeder
      we will get back to you in a bit!

      Best!

      Marius

      www.mariusjopen.world

      1 Reply Last reply
      0
      • arminunruhA Offline
        arminunruhA Offline
        arminunruh
        Global Moderator
        wrote on last edited by
        #3

        oh hmm

        if you'd do in lay options -> "custom css & html" -> "custom head content":

        <script>
        frontendPassedData.siteUrl = "http://google.com";
        </script>
        

        now lay theme would try to load images from:
        http://google.com/wp-content/uploads/2019/04/3.jpg

        1 Reply Last reply
        0
        • M Offline
          M Offline
          michaelmaeder
          wrote on last edited by
          #4

          Thanks Armin and Marius,

          I just tried this out. Setting the js object frontendPassedData.siteUrl does work for some images, but not for others apparently. I currently have no public example, but will get back to this soon once the page is launched. If you have any tips in the meantime, that would be much appreciated.

          Thanks

          1 Reply Last reply
          0
          • M Offline
            M Offline
            michaelmaeder
            wrote on last edited by
            #5

            Never mind, after reselecting all images in the content, now the CDN url is set properly. Somehow it seems this does not work for images that have been selected before I have set the siteURL accordingly.

            1 Reply Last reply
            0
            • mariusjopenM Offline
              mariusjopenM Offline
              mariusjopen
              Global Moderator
              wrote on last edited by
              #6

              Dear @michaelmaeder
              ok. Thank you for letting us know.

              Best!

              Marius

              www.mariusjopen.world

              1 Reply Last reply
              0
              • M Offline
                M Offline
                michaelmaeder
                wrote on last edited by
                #7

                Actually now I realised all links set on Images within the gridder are also set to the CDN, which makes them not work anymore. The only navigation that still works is the main navigation. All other navigation within the site is broken after setting the frontendPassedData.siteUrl.

                So setting frontendPassedData.siteUrl is fixing the CDN for images but breaking the page navigation within the page (not the main menu).

                Is there a way to just set the path for assets and not for navigational links?

                Thank you!

                1 Reply Last reply
                0
                • M Offline
                  M Offline
                  michaelmaeder
                  wrote on last edited by
                  #8

                  @mariusjopen Sorry forgot to mention you int he earlier post. Hope you see this. Thanks for any tips :-)

                  1 Reply Last reply
                  0
                  • arminunruhA Offline
                    arminunruhA Offline
                    arminunruh
                    Global Moderator
                    wrote on last edited by
                    #9

                    cdn integration should work now with the latest lay theme versions

                    1 Reply Last reply
                    0
                    • M Offline
                      M Offline
                      michaelmaeder
                      wrote on last edited by
                      #10

                      Thanks Armin, so I guess I have to go to work and migrate all that CSS over.

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      I also code custom websites or custom Lay features.
                      šŸ’æ Email me here: šŸ’æ
                      info@laytheme.com

                      Before you post:
                      1. When using a WordPress Cache plugin, disable it or clear your cache.
                      2. Update Lay Theme and all Lay Theme Addons
                      3. Disable all Plugins
                      4. Go to Lay Options → Custom CSS & HTML, click "Turn Off All Custom Code", click "Save Changes"

                      This often solves issues you might run into

                      When you post:
                      1. Post a link to where the problem is
                      2. Does the problem happen on Chrome, Firefox, Safari or iPhone or Android?
                      3. If the problem is difficult to explain, post screenshots / link to a video to explain it
                      Online Users
                      Forgot your key, lost your files, need a previous Lay Theme or Addon version? Go to www.laykeymanager.com
                      laytheme.com
                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Recent
                      • Tags
                      • Popular
                      • Users
                      • Search