0

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?

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 &&.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.