I want to deregister some styles when a user is not logged in, but not on a particular page.
I tried adding this code into "functions.php" of BuddyBoss Child Theme, but on that page it seems the script is executed anyway.
The script must be executed when the user is not logged in, but not in the page "forums".
I’ve already tried adding to that page critical CSS but the layout is not fine anyway, so I decided to make an exception in functions.php for the page "forums".
add_action('wp_enqueue_scripts','my_deregister_custom',100);
function my_deregister_custom() {
if ( !is_user_logged_in() ) {
wp_deregister_style('dashicons');
if ( !is_page( array(51519,'forums'))) {
wp_deregister_style('buddyboss-theme-forums');
wp_deregister_style('bp-mentions-css');
wp_deregister_style('learndash-front');
wp_deregister_style('buddyboss-theme');
wp_deregister_style('ldx-design-upgrade-learndash');
wp_deregister_style('buddyboss-theme-learndash');
wp_deregister_style('elementor-frontend');
}
}
}
Here I attach a screenshot of the page edit, where you can see the page ID, the slug and the url.
2
Answers
Please replace with below of the code and check agian. i hope it will work…
Seems the assets already enqueued. Try to use
wp_dequeue_style()
instead ofwp_deregister_style()