How to enqueue/register JS and CSS files to elementor addon


Hope you are doing well.
I designed a elementor widget (slider) using slick carousel. when I am inserting the widget in elementor page, it is working fine when opening the page in browser ([screen shot][1]). The only problem that I have is, the slider not working in elementor editing area ([screen shot][2])

Based on elementor docs I tried to enqueue/register the JS and CSS files related to slider by adding this function:

    function my_plugin_preview_scripts() {

    wp_register_script( 'preview-script-1', plugins_url( 'assets/js/preview-script-1.js', __FILE__ ) );
    wp_register_script( 'preview-script-2', plugins_url( 'assets/js/preview-script-2.js', __FILE__ ), [ 'external-library' ] );
    wp_register_script( 'external-library', plugins_url( 'assets/js/libs/external-library.js', __FILE__ ) );

    wp_enqueue_script( 'preview-script-1' );
    wp_enqueue_script( 'preview-script-2' );
add_action( 'elementor/preview/enqueue_scripts', 'my_plugin_preview_scripts' );

But unfortunately it is not working for me and still I am facing the same issue and I know why it is not working that is because I am not understanding the PHP fully and I dont know where should add this code.

Now I really need your help.

Mohammad Ali Khodadadi 8 months 2022-06-23T02:55:57-05:00 0 Answers 0 views 0

Leave an answer