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
}
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.