Created
October 11, 2017 07:33
-
-
Save mariusgnicula/2261bb9548ef1a5388704bf0ef02528b to your computer and use it in GitHub Desktop.
How to include JS into custom Elementor Widget
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
This will only load this section if you are in the editor. The sad thing is that you will have some duplicate code, but so far I've not found a better way. Include only what you need for that particular widget. | |
Hope this helps! | |
Have a great day. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Excuse me. What does the "Plugin" stand for ?