为了账号安全,请及时绑定邮箱和手机立即绑定

如何在 Elementor (Pro) 中取消注册/出队 jquery.sticky.js?

如何在 Elementor (Pro) 中取消注册/出队 jquery.sticky.js?

PHP
慕斯709654 2021-11-26 16:12:10
我想通过注销不必要的外部资源来提高页面速度。我已经设法删除了大部分外部脚本,Elementor 默认在前端加载。但是,我无法以某种方式删除 jQuery 插件Sticky。我想这与成为 Elementor Pro 的一部分有关。我已经尝试查看 jQuery 依赖项,但这对我不起作用。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 回答

?
素胚勾勒不出你

TA贡献1827条经验 获得超9个赞

Elementor 和 Elementor PRO 注册和排队一些具有依赖关系的脚本。对于删除,您需要在没有特定脚本的情况下取消注册并再次注册(例如没有“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 );


查看完整回答
反对 回复 2021-11-26
?
茅侃侃

TA贡献1842条经验 获得超21个赞

我找到了一个适合我的解决方案。如果您有更清洁的解决方案,请告诉我:)


    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' );```


查看完整回答
反对 回复 2021-11-26
?
鸿蒙传说

TA贡献1865条经验 获得超7个赞

如果您知道正在添加的操作的名称,您可以使用该功能,remove_action( $tag, $function_to_remove, $priority )或者您可以使用wp_dequeue_script( $handle )

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

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


查看完整回答
反对 回复 2021-11-26
  • 3 回答
  • 0 关注
  • 157 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信