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.
CodePudding user response:
Please replace with below of the code and check agian. i hope it will work...
add_action('wp_enqueue_scripts','my_deregister_custom',1000);
function my_deregister_custom() {
if ( !is_user_logged_in() ) {
wp_deregister_style('dashicons');
// When Page 51519 (ID) is being displayed.
// is_page( 51519 );
// When the Page with a post_name (slug) of "forums" is being displayed.
//is_page( 'forums' );
if ( !is_page( 'forums') || !is_page(51519) ) {
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');
}
}
}
CodePudding user response:
Seems the assets already enqueued. Try to use wp_dequeue_style()
instead of wp_deregister_style()