The motto "In God We Trust" predates the Pledge to the Flag, the original version of the Pledge of Allegiance, authored in 1892.
for a detailed history of the pledge and it's modifications.
IN GOD WE TRUST first appeared on the 1864 two-cent coin. The Act of May 18, 1908, made it mandatory on all coins upon which it had previously appeared. IN GOD WE TRUST was not mandatory on the one-cent coin and five-cent coin. It could be placed on them by the Secretary or the Mint Director with the Secretary's approval.
The motto has been in continuous use on the one-cent coin since 1909, and on the ten-cent coin since 1916. It also has appeared on all gold coins and silver dollar coins, half-dollar coins, and quarter-dollar coins struck since July 1, 1908.