Support

Account

Home Forums Add-ons Flexible Content Field Flexible Content Layout Conditional Reply To: Flexible Content Layout Conditional

  • There are a couple of ways to do what you what. The first is to enqueue the script in the footer when you actually output the “slider”. This will work, and you’ll only get one instance of the script no matter how many times it’s called.

    simple example:

    
    while (have_rows('flex-field')) {
      the_row();
      if (get_row_layout()) == 'slider') {
        // enqueue slider script with $in_footer set to true
      }
    }
    

    Another way is to get the flex field using get_post_meta(). When you get the flex field this way it will return an array containing a list of layout names.

    
    $layouts = get_post_meta($post_id, 'flex-field-name', true);
    if (is_array($layouts) && in_array('slider', $layouts)) {
      // enqueue slider script
    }