Between 1914-1944 most advanced nation kept getting on and off the gold standard to balance the need of expansionary monetary policy to finance the war and fight the great depression with the need of gold standard that was mostly needed to stabilize the economy, favour free trade and ideologically preferred (having a currency pegged to the gold was seen as a sign of strenght and that things were back to normal).
In 1944 the Allied power met to discuss the post-war financial system and what emerged was the so called Bretton Woods system. The objective was to favour trade and economic growth after the war and to do that it set a system where the dollar was on the gold standard and the other currencies were pegged to the dollar (gold-dollar standard).
The system worked in part bringing one of the longest period of peace but with time started to show problems. In particular for the US the problems were that as the balance of payments (money flowing in-money flowing out) became more and more negative, more dollars were held in the hands of foreigners and as 1964 dollars held by foreigners surpassed the us gold reserves, so the goverment start fearing for the credibility of the gold standard as a back run of the federal reserved would have drained gold reserves.
Meanwhile the US could not reduce the balance of payment because it would have drained international liquidity and stopped trade (in particular european countries used the dollar to trade between themeselves and between europe and US).
Moreover many europeans leader, De Gaulle in particular, resented the role of the US and wanted to change their dollar reserves in gold.
With some adjustements to the system and persuasion on some european allies to keep the dollars the system kept going until the late 60s.
In the meanwhile the goverment started to need money to finance the vietnam war and started the great society program. At the time was belived that an increase in inflation would automatically cause unemployment to fall and GDP to grow (this was the first formulation of the so called philips curve), so the Fed starting in 1965 started to pursue higher inflation with the objective of stimulating the economy but this increased the negative balance of payments and despite the european attept to counteract this, nothing changed.
Several others events (like the 1967 devaluation of the sterling) made the valuation at 35$ the ounce more and more difficult to mantain. Despite US pressure in 1971 France and the UK announced their intention to convert their dollar reserves into gold, at this point Nixon intervened and stopped conversion. The system was revised with gold being set at 38 and then 42 dollar the ounce but it was clear the system had failed. One by one all nations left the gold dollar standard and adopting a managed floating system and finally even the dollar was left free to float in 1976.