Support

Account

Home Forums Add-ons Flexible Content Field Check if layout is used

Solved

Check if layout is used

  • Hi.

    I have a Flexible Content Layout to display a Google Map field.
    So in my functions.php I added this:
    wp_enqueue_script( 'google-map-api', 'http://maps.googleapis.com/maps/api/js?sensor=false', array(), '3.0.0', true );

    Now I only want to load this if the layout ‘Google Map’ is used. How can I check this?

    Greetings
    Patrick

  • You could register your script in functions.php and then enqueue it right where you need. So, just as a mere example:
    in functions.php

    wp_register_script( 'gmaps','https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false', array(), '1.0', true );
    

    and then in your layout code:

    elseif( get_row_layout() == 'map' ):
    
            $google_maps = get_sub_field('google_maps');
            if( !empty($google_maps) ):
            wp_enqueue_script('gmaps');
    

    This will load google’s .js in footer just when you need it.

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

The topic ‘Check if layout is used’ is closed to new replies.