A suburban San Diego teenager who was barred from wearing a T-shirt with anti-gay rhetoric to class lost a bid to have his high school's dress code suspended Thursday after a federal appeals court ruled the school could restrict what students wear to prevent disruptions.

The ruling by the San Francisco-based 9th U.S. Circuit Court of Appeals addressed only the narrow issue of whether the dress code should be unenforced pending the outcome of the student's lawsuit.

A majority of judges said, however, that Tyler Chase Harper was unlikely to prevail on claims that the Poway Unified School District violated his First Amendment rights to freedom of speech and religion for keeping him out of class when he wore a shirt with the message "homosexuality is shameful."

Tyler Chase Harper sued the Poway Unified School District in San Diego federal court after the principal at Poway High School refused to let the student attend class wearing a T-shirt scrawled with the message "homosexuality is shameful."

Harper was a sophomore at Poway High in 2004 when he wore the T-shirt the day after a group called the Gay-Straight Alliance held a "Day of Silence" to protest intolerance of gays and lesbians. The year before, the campus was disrupted by protests and conflicts between students over the Day of Silence.

After Harper refused to take off the T-shirt, Poway High School's principal kept Harper out of class and assigned him to do homework in a conference room for the rest of the day. He was not suspended from school.

On Thursday, the three-judge appeals court panel said "the school is permitted to prohibit Harper's conduct...if it can demonstrate that the restriction was necessary to prevent either the violation of the rights of other students or substantial disruption of school activities."

The opinion, written by Judge Stephen Reinhardt and joined by Judge Sydney Thomas for a 2-1 ruling, didn't decide the merits of the student's lawsuit, which will be heard in federal court in San Diego.

Judge Alex Kozinski wrote a blistering dissent, arguing that the high school had in effect authorized a heated debate over sexual orientation when it allowed the "Day of Silence."

"Harper's T-shirt was not an out-of-the-blue affront to fellow students who were minding their own business," Kozinski wrote. "Rather, Harper wore his T-shirt in response to the Day of Silence, a political activity that was sponsored or at the very least tolerated by school authorities."

Jack Sleeth, a school district attorney, said that the 9th Circuit ruling supports the district's prohibition against T-shirts with messages that are offensive to some.

"When it violates the rights of other, then it can be prohibited," Sleeth said. "It is that simple of an issue."

Robert Tyler, an attorney for Harper, said he may wait until the main case is decided before determining if further appeals are necessary.

"Mr. Harper's speech was censored," Tyler said. "There wasn't any disruption, but there was concern that it was politically incorrect."