City schools will have to start teaching sex education to their students again — that’s an order.

Schools Chancellor Dennis Walcott last night sent a carefully worded e-mail to all middle- and high-school principals informing them that they no longer have a choice about whether they want their students to learn such things as how to put on a condom and the dangers of sexual promiscuity.

“While many of our schools have already voluntarily taken steps to include sex education in their curriculum, some have not, leaving us with an uneven system that I believe does not serve our students well,” Walcott wrote.

“We have students who are having sex before the age of 13; students who have had multiple sexual partners; and students who aren’t protecting themselves against sexually transmitted diseases and HIV/AIDS.

“As a parent and a grandparent — and as the person responsible for ensuring that all of our public-school students receive a high-quality education — that is very concerning,” Walcott said.

So starting next spring, students will required to take sex ed. during one semester, as either a sixth- or seventh-grader and then again in high school, hopefully in ninth or 10th grade, Walcott said.

Still, Walcott attempted to soften the news for parents who would oppose their kids getting educated in the ways of birth control.

“As with our HIV/AIDS curriculum, we will offer a parental opt-out on specific lessons involving prevention and birth control,” he said.

But what parents can’t prevent their kids from learning are such subjects as what risky behaviors can cause HIV, pregnancy or sexually transmitted diseases, officials said.

In making the move, Walcott is reversing a decision made more than two decades ago to ban mandated sex ed. after religious groups fought against it in the 1980s.

He indicated that the plan is aimed at helping minority students, who according to statistics have much higher rates of pregnancy and sexually transmitted diseases than whites.

A survey of middle-school principals last year showed that 64 percent were using uniform, recommended sex-ed. lesson plans, officials said.