Skip to content

Instantly share code, notes, and snippets.

View mariusgnicula's full-sized avatar

Marius Nicula mariusgnicula

View GitHub Profile
@mariusgnicula
mariusgnicula / gist:2261bb9548ef1a5388704bf0ef02528b
Created October 11, 2017 07:33
How to include JS into custom Elementor Widget
Include your JS into a normal file, just how you are used to and enqueue it with wp_enqueue_script. This will not work in the editor, because you want the functions to fire when you add them.
At the beginning of your widget file, add ‘use Elementor\Plugin;’.
Then at the end of the render() function in your PHP, add this:
<?php if ( Plugin::$instance->editor->is_edit_mode() ) : ?>
<script>Your code here</script
<?php