The US Flag Code (Title 4 Chapter 1 of the US Code) governs the care and treatment of the US flag. The Pledge of Allegiance was first added to the US Flag Code in June 1942, and is covered by Chapter 1, Section 4.
The words “under God” were added to the pledge in Dec. 1954, and the full code has been amended several times since.
Section 10 of the US Flag Code allows for the US President to modify the US Flag Code.
Note that after each code section are links showing when the law was added and each time it was revised, provided by the Legal Information Institute of Cornell University.
4 U.S. Code § 4 – Pledge of allegiance to the flag; manner of delivery
The Pledge of Allegiance to the Flag: “I pledge allegiance to the Flag of the United States of America, and to the Republic for which it stands, one Nation under God, indivisible, with liberty and justice for all.”, should be rendered by standing at attention facing the flag with the right hand over the heart. When not in uniform men should remove any non-religious headdress with their right hand and hold it at the left shoulder, the hand being over the heart. Persons in uniform should remain silent, face the flag, and render the military salute. Members of the Armed Forces not in uniform and veterans may render the military salute in the manner provided for persons in uniform.(Added Pub. L. 105–225, § 2(a), Aug. 12, 1998, 112 Stat. 1494; amended Pub. L. 107–293, § 2(a), Nov. 13, 2002, 116 Stat. 2060; Pub. L. 113–66, div. A, title V, § 586, Dec. 26, 2013, 127 Stat. 777.)
4 U.S. Code § 10 – Modification of rules and customs by President
Any rule or custom pertaining to the display of the flag of the United States of America, set forth herein, may be altered, modified, or repealed, or additional rules with respect thereto may be prescribed, by the Commander in Chief of the Armed Forces of the United States, whenever he deems it to be appropriate or desirable; and any such alteration or additional rule shall be set forth in a proclamation.(Added Pub. L. 105–225, § 2(a), Aug. 12, 1998, 112 Stat. 1498.)