No, you do not have to stand up and take off your hat during the Pledge of Allegiance. In the 1943 case West Virginia Board of Education v. Barnette, the Supreme Court said students who objected to the flag salute and mandatory pledge recitation for religious reasons could not be forced to participate.
Although Barnette pertains to reciting the pledge, in the case Lipp v. Morris (1978) the 3rd U.S. Circuit Court of Appeals struck down a New Jersey statute requiring a student to stand during the pledge as unconstitutional.
As explored in Lipp and Barnette, a fundamental constitutional right is that no government official at any level can force conduct from any citizen regarding an expression of religion, politics, nationalism, or matter of opinion.