如何正确删除未登录和仅用于首页的样式

时间:2020-03-25 作者:Uzair

我正在尝试删除非loggedin用户的样式(&M);仅首页。

我正在尝试,但没有成功。知道我哪里出错了吗?

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

    }
}

1 个回复
SO网友:mikerojas

看起来您可能需要使用Elementor Pro独有的自定义挂钩:https://code.elementor.com/php-hooks/#elementorfrontendbefore_enqueue_scripts

下面的示例未经测试,但针对您的用例进行了修改。

// 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\' );
    }
} );

相关推荐

初学者问题:通过管理Web界面访问Functions.php以导入自定义帖子类型?

是否可以访问这些功能。php文件仅仅使用管理web界面?我正在尝试访问以前创建的(手动编码的)自定义帖子类型,我不得不跳过很多障碍,因为我无法访问函数中的代码。php文件。我已经浏览了很多帮助页面,但建议的步骤似乎总是涉及到函数。php文件(我无法访问)或使用插件中的导入/导出工具,该插件首先创建了自定义帖子类型(据我所知,没有使用任何插件)。这似乎是一个非常基本的问题,但我一辈子都想不出来。任何帮助都将不胜感激!