pixel-d
11/29/2017 - 6:54 PM

Localize Script - Pass variable to enqueued script

if ( is_singular( 'cpt' ) ) {
  wp_enqueue_script( 'googlemaps' );
  wp_enqueue_script( 'maps' );
 
  $marker_option = 'false';
  if (is_singular( 'commercial_project' )) {
    $marker_option = 'true';
  }
  $map_options = array(
    'show_markers' => $marker_option,
  );
  wp_localize_script( 'maps', 'map_options', $map_options );
}