The pledge became the official Pledge of Allegiance by an act of Congress on June 22, 1942. In 1943, the Supreme Court ruled that children cannot be required to recite it.
The pledge was originally published in 1892 in The Youth's Companion. It was written by Francis Bellamy as a pledge to be said aloud on Columbus Day, and the original text was: "I pledge allegiance to my flag and the Republic for which it stands, one nation, indivisible, with liberty and justice for all."
It was first changed in 1923 at the first National Flag Conference in Washington, when "my flag" was replaced with "the Flag of the United States of America" for clarity. In 1954, Congress and President Eisenhower approved adding the phrase "under God" to the pledge.
Official pledge 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."