Remove dashicons.min.css conditionally

admin2025-06-04  12

Trying to remove dashicons for non-logged in users excluding specific pages and specific categories with the following:

add_action( 'wp_enqueue_scripts', 'go_dequeue_dashicons' );
function go_dequeue_dashicons() {
if ( ! is_user_logged_in() ) {
    if ( !is_page( array( 9, 10 ) ) || !in_category( array( 29, 2 ) ) ) {
        wp_deregister_style( 'dashicons' );
    }
  }
}

The code works if I do not use the OR condition. In other words it works if I apply a sole IF statement either for the specific pages or for the specific categories. It doesn’t work if I use both IF statements under the OR condition. Which is the correction needed?

Trying to remove dashicons for non-logged in users excluding specific pages and specific categories with the following:

add_action( 'wp_enqueue_scripts', 'go_dequeue_dashicons' );
function go_dequeue_dashicons() {
if ( ! is_user_logged_in() ) {
    if ( !is_page( array( 9, 10 ) ) || !in_category( array( 29, 2 ) ) ) {
        wp_deregister_style( 'dashicons' );
    }
  }
}

The code works if I do not use the OR condition. In other words it works if I apply a sole IF statement either for the specific pages or for the specific categories. It doesn’t work if I use both IF statements under the OR condition. Which is the correction needed?

Share Improve this question edited Jan 9, 2019 at 18:57 fuxia 107k39 gold badges255 silver badges461 bronze badges asked Jan 9, 2019 at 17:10 MichaelMichael 32 silver badges5 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

Try this.

add_action( 'wp_enqueue_scripts', 'go_dequeue_dashicons' );
function go_dequeue_dashicons() {
    if ( ! is_user_logged_in() && !is_page( array( 9, 10 ) ) && !in_category( array( 29, 2 ) ) ) {
        wp_deregister_style( 'dashicons' );
    }
}

I basically just combined the IF statements and changed || to &&.

转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1749025354a315725.html

最新回复(0)