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.

“The only remaining exception to the general rule is membership in a religious organization,” said Fourth District Court of Appeal Justice Richard D. Fybel, chair of the Supreme Court’s Advisory Committee on the Code of Judicial Ethics. “One other exception — belonging to a military organization — was eliminated as well, because the U.S. armed forces no longer restrict military service based on sexual orientation.”

Of 47 states that ban judges from joining discriminatory groups, 22 states, including California, include a bar on groups that show bias on the basis of sexual orientation. California was the only one of those states that made exceptions for youth groups.

Judges will have until Jan. 21, 2016 to comply with the new rule.