pierrebalian
9/25/2017 - 5:44 PM

Conditionally Enqueue Based On A Flex Field

Conditionally Enqueue Based On A Flex Field

<?php

	/**
	 * For determining if specific scripts, tied to specific content blocks, need to be enqueued.
	 *
	 * @var array $content_blocks
	 */
	$content_blocks = get_post_meta( get_the_ID(), 'content_blocks', true );


	/**
	 * Conditionally enqueue Theme's Google Map JS if 'find_a_dealer_map_block is present.
	 */
	if ( ! empty( $content_blocks ) && in_array( 'find_a_dealer_map_block', $content_blocks, true ) ) {

		/** Enqueue Theme's Google Map JS. */
		wp_enqueue_script(
			'cfmoto-google-map-js',
			get_template_directory_uri() . '/js/cfmoto-google-map.js',
			array( 'google-maps-api' ),
			'1.0.0',
			true
		);
	}