Allow Custom JS to run in preview
-
/*** * Runs Custom JS in preview mode * * Activating Elementor 'safe mode' auto-disables Custom JS (in case of faulty JS) */ function wp_ea_custom_js() { $post_id = get_the_ID(); if ( ! $post_id || ! \Elementor\Plugin::instance()->preview->is_preview_mode( $post_id ) ) { return; } $custom_js = get_post_meta( $post_id, '_eael_custom_js', true ); if ( $custom_js ) { $localize_objects = apply_filters( 'eael/localize_objects', [ 'ajaxurl' => admin_url( 'admin-ajax.php' ), 'nonce' => wp_create_nonce( 'essential-addons-elementor' ), 'i18n' => [ 'added' => __( 'Added ', 'essential-addons-for-elementor-lite' ), 'compare' => __( 'Compare', 'essential-addons-for-elementor-lite' ), 'loading' => esc_html__( 'Loading...', 'essential-addons-for-elementor-lite' ) ], 'page_permalink' => get_the_permalink(), 'cart_redirectition' => get_option( 'woocommerce_cart_redirect_after_add' ), 'cart_page_url' => function_exists( 'wc_get_cart_url' ) ? wc_get_cart_url() : '', 'el_breakpoints' => method_exists( \Elementor\Plugin::$instance->breakpoints, 'get_breakpoints_config' ) ? \Elementor\Plugin::$instance->breakpoints->get_breakpoints_config() : '', ] ); printf( '<script>%1$s</script>', 'var localize =' . wp_json_encode( $localize_objects ) ); printf( '<script id="eael-inline-js">%s</script>', $custom_js ); } } add_action( 'wp_footer', 'wp_ea_custom_js', 100 );
Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
- The topic ‘Allow Custom JS to run in preview’ is closed to new replies.