• I’m using Elementor and I’ve added a code snippet on a template. This snippet loads multiple Before and After instances dynamically. If the fields are populated then one, two, three or four B/As will show. If none of them are populated then nothing shows. But we’re having an issue, if there are more than one B/A on a page the second through fourth don’t always show, not until the page is refreshed. This doesn’t happen all of the time, but often enough to be a problem. It doesn’t seem to be a browser issue, happens on Windows and Mac, Firefox and Safari.

    Here is the code snippet if this helps, the snippet is added to the template page via a shortcode:

    <?php
    $before1 = get_field("before_image_1");
    $after1 = get_field("after_image_1");
    $before2 = get_field("before_image_2");
    $after2 = get_field("after_image_2");
    $before3 = get_field("before_image_3");
    $after3 = get_field("after_image_3");
    $before4 = get_field("before_image_4");
    $after4 = get_field("after_image_4");
    ?>

    <?php if (!empty($before1)) {
    ?>
    <!-- <h2 style="color: white; background: #416BA9; font-size: 14.4px; line-height: 26px; font-family: 'Roboto'; font-weight: 500; letter-spacing: 2px; padding: 2px 2px 2px 10px;">BEFORE AND AFTER</h2> -->

    [twenty20 img1="<?php echo $before1; ?>" img2="<?php echo $after1; ?>" offset="0.5"]
    <?php } ?>

    <?php if (!empty($before2)) {
    ?>
    [twenty20 img1="<?php echo $before2; ?>" img2="<?php echo $after2; ?>" offset="0.5"]
    <?php } ?>

    <?php if (!empty($before3)) {
    ?>
    [twenty20 img1="<?php echo $before3; ?>" img2="<?php echo $after3; ?>" offset="0.5"]
    <?php } ?>

    <?php if (!empty($before4)) {
    ?>
    [twenty20 img1="<?php echo $before4; ?>" img2="<?php echo $after4; ?>" offset="0.5"]
    <?php } ?>

    Thanks for any help you can lend.

    The page I need help with: [log in to see the link]

Viewing 5 replies - 1 through 5 (of 5 total)
  • D9Dan

    (@d9dan)

    I just wondered if you managed to get to the bottom of this as I am having the same issue on a newly built website using Elementor.

    There are multiple A/B images on a page and sometimes they all show, sometimes 3/4 show, sometimes only 1 shows. They all then display correctly after a refresh.

    Just had a look at the page you had issues with and all the images display correctly so hoping you found a fix?

    Thread Starter dave9621

    (@dave9621)

    Hey D9Dan, I think I solved my issue, I used ChatGPT to give me some advice. Here’s what it told me to try:

    1. Defer Javacript Execution by adding this JS code (I put it in the header):
      jQuery(window).on(‘load’, function() {
      jQuery(‘.twentytwenty-container’).each(function() {
      jQuery(this).twentytwenty();
      });
      });
    2. Disable Lazy Loading for Twenty20 Images
    3. Check for Conflicting Scripts
    4. Increase Load Delay for Widgets (using custom JS):
      jQuery(document).ready(function() {
      setTimeout(function() {
      jQuery(‘.twentytwenty-container’).twentytwenty();
      }, 500); // Increase delay as necessary
      });

    I hope one of these ideas helps you.

    Thread Starter dave9621

    (@dave9621)

    Dan, I see that I can Share my ChatGpt with you.

    https://chatgpt.com/share/67165fb9-2f2c-8002-a84d-225c59f0536e

    D9Dan

    (@d9dan)

    Thanks Dave, I can confirm those 2 bits of custom JS appear to have fixed the issue. God bless ChatGPT!

    Thread Starter dave9621

    (@dave9621)

    That’s awesome! I got the idea about asking ChatGPT from a YouTuber I follow, he had this great vid on how to make AI answer your tech questions. Have a look if you’re interested.

Viewing 5 replies - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.