skip to Main Content

I want to increase my page speed by deregistering unnecessary external resources. I already managed to remove most of the external scripts, Elementor loads by default on the frontend. However, I can’t remove the jQuery plugin Sticky somehow. I guess it has to do with being a part of Elementor Pro.

I’ve already tried to look under jQuery depencies, however that didn’t work for me.

function remove_jquery_sticky() {
    if ( ! is_admin()) {
        wp_deregister_script( 'sticky' );
    }
}
add_action( 'elementor/frontend/after_register_scripts', 'remove_jquery_sticky' );

I expect the jQuery plugin not to load on the frontend, however it still does.

3

Answers


  1. Chosen as BEST ANSWER

    I have found a solution that works for me. If you've a cleaner solution, please let me know :)

        if(is_front_page()) {
            // Dequeue and deregister elementor-sticky
            wp_dequeue_script( 'elementor-sticky' );
            wp_deregister_script( 'elementor-sticky' );
    
            // Dequeue and deregister elementor-pro-frontend
            wp_dequeue_script( 'elementor-pro-frontend' );
            wp_deregister_script( 'elementor-pro-frontend' );
    
            // Re-register elementor-frontend without the elementor-sticky dependency.
            $suffix = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '' : '.min';
            wp_register_script(
                    'elementor-pro-frontend',
                    ELEMENTOR_PRO_URL . 'assets/js/frontend' . $suffix . '.js',
                    [
                        'elementor-frontend-modules',
                    ],
                    ELEMENTOR_VERSION,
                    true
                );
        }
    }
    add_action( 'wp_enqueue_scripts', 'elementor_pro_frontend_scripts' );```
    

  2. If you know the name of the action that is being added you can use the function remove_action( $tag, $function_to_remove, $priority ) or you can use wp_dequeue_script( $handle )

    https://codex.wordpress.org/Function_Reference/remove_action

    https://codex.wordpress.org/Function_Reference/wp_dequeue_script

    Login or Signup to reply.
  3. Elementor and Elementor PRO register and enqueue some scripts with dependences. For remove you need deregister and register again without specific script (example without ‘elementor-sticky’).

    if(is_front_page()) {
    
            // Dequeue and deregister elementor-pro-frontend
            wp_deregister_script( 'elementor-pro-frontend' );
    
            // Re-register elementor-frontend without the elementor-sticky dependency.
            $suffix = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '' : '.min';
            wp_register_script(
                    'elementor-pro-frontend',
                    ELEMENTOR_PRO_URL . 'assets/js/frontend' . $suffix . '.js',
                    [
                        'elementor-frontend-modules',
                    ],
                    ELEMENTOR_VERSION,
                    true
                );
        }
    }
    add_action( 'wp_enqueue_scripts', 'elementor_pro_frontend_scripts', 20 );
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search