最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

functions - How to properly remove style for non logged in and front page only

programmeradmin3浏览0评论

I am trying to remove style for non loggedin user & front page only.

i am trying this but didn't work. any idea where i am making mistake?

add_action( 'wp_print_styles', 'my_deregister_style', PHP_INT_MAX );

function my_deregister_style() {
    if ( is_front_page() && !is_user_logged_in() ) {
        wp_dequeue_style( 'elementor-pro' );
        wp_deregister_style( 'elementor-pro' );

    }
}

I am trying to remove style for non loggedin user & front page only.

i am trying this but didn't work. any idea where i am making mistake?

add_action( 'wp_print_styles', 'my_deregister_style', PHP_INT_MAX );

function my_deregister_style() {
    if ( is_front_page() && !is_user_logged_in() ) {
        wp_dequeue_style( 'elementor-pro' );
        wp_deregister_style( 'elementor-pro' );

    }
}
Share Improve this question asked Mar 25, 2020 at 17:20 UzairUzair 111 bronze badge
Add a comment  | 

1 Answer 1

Reset to default 0

Looks like you may need to use a custom hook unique to Elementor Pro: https://code.elementor/php-hooks/#elementorfrontendbefore_enqueue_scripts

The below example is un-tested but modified for your use case.

// Note: I think all you need is to dequeue the style to remove from the page
add_action( 'elementor/frontend/after_enqueue_styles', function() {
    if ( is_front_page() && !is_user_logged_in() ) {
        wp_dequeue_style( 'elementor-pro' );
    }
} );
发布评论

评论列表(0)

  1. 暂无评论