Roots Discourse

Conditionally load external JS on specific condition


I’d need to conditionally load a google map JS when the user is viewing a page in “readonly mode” $canEdit = false while, if he is logged, or is watching a page one can edit $canEdit = true such file must not be loaded or it creates a conflict with ACF jquery maps input field.

I can’t do it in the setup.php with wp_enqueue_script as I need a specific condition to be applied: $canEdit = true and don’t wan’t to echo a tag…

is there a cleaner way to do this?


could this be a correct solution?


 @if(is_single() && !App::canEdit())
    <script src=""></script>

Hm, but isn’t there also JavaScript that initialized Google Maps on the page?
This enqueue only loads Google Maps API and makes it available.

This topic was automatically closed after 42 days. New replies are no longer allowed.