SAN FRANCISCO — California’s Supreme Court voted Friday to prohibit state judges from belonging to the Boy Scouts on grounds that the group discriminates against gays.

The court said its seven justices unanimously voted to heed a recommendation by its ethics advisory committee barring judges’ affiliation with the organization.

In 1996 the state Supreme Court banned judges from belonging to groups that discriminate on the basis of sexual orientation, but made an exception for nonprofit youth organizations.

The Supreme Court’s Advisory Committee on the Code of Judicial Ethics in February recommended eliminating the exception to enhance public confidence in the judiciary.

The group allows the participation of openly gay boys but continues to prohibit gay and lesbian adults from serving as leaders.

The Boys Scouts of America couldn’t immediately be reached for comment.

The proposed rule change was sent out for public comment last year, and the change was supported by the California Judges Association, the court said.