Support

Home Forums Add-ons User Submitted ACF IF/THEN in Javascript

Solved

ACF IF/THEN in Javascript

  • Is it possible to use if/then ACF within Javascript? I had a client who had magic fields and we switched them to ACF.

    They have this snippet in their single-article.php code that needs to have a global options page fallback.

    <script>
    jQuery(document).ready(function($) {
    var delay = ‘<?php the_field(‘popup_delay’); ?>’;
    setTimeout(function() {
    $(‘.popup_overlay’).addClass(‘active’);
    }, delay);
    });
    </script>

    So essentially we’re trying to achieve the following: ” If they find the popup delay on that specified page template, then they would apply this script, if not, they would apply script B that calls the ‘popup_delay’, ‘options’.

    I’ve perused the forums and web with no success. I appreciate any and all insight.

    Thank you very much,

  • 
    <script>
      jQuery(document).ready(function($) {
        var delay = '<?php 
          if (get_field('popup_delay')) {
            the_field('popup_delay');
          } else {
            the_field('popup_delay', 'options');
          }
        ?>';
        setTimeout(function() {
          $('.popup_overlay').addClass('active');
        }, delay);
      });
    </script>
    
  • Oh my goodness thank you so much!! That makes complete sense now that I see it! I truly appreciate your insight!

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.