亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何在 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條經驗 獲得超22個贊

我找到了一個適合我的解決方案。如果您有更清潔的解決方案,請告訴我:)


    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 關注
  • 214 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號