President Donald Trump has directed the Pentagon to declare an indefinite ban on transgender individuals joining the military, but he appeared to leave open the possibility of allowing some already in uniform to remain in the military.

The Obama administration had changed a longstanding policy in July 2016, declaring that troops could serve openly as transgender individuals. And it set a July 2017 deadline for determining whether transgender people could be allowed to enter the military. Defence Secretary Jim Mattis had delayed that to 1 January, 2018, and Mr Trump has now instructed Mr Mattis to extend it indefinitely.

But on the question of what will happen to those transgender individuals who already are serving openly — estimated to number in the low hundreds — Mr Trump seemed to leave some wiggle room for exceptions. A White House official who briefed reporters on the presidential order would not say whether Trump would permit any exceptions.

That official, who spoke on condition of anonymity under ground rules set by the White House, said Mr Mattis has been directed to take a number of factors into consideration in determining how to deal with transgender individuals already serving. Those factors are to include broad measures such as “military effectiveness,” budgetary constraints, and “unit cohesion,” as well as other factors Mr Mattis deems “relevant.” It was not clear whether that means it is possible for Mr Mattis to come to the conclusion that some transgender troops should be allowed to remain.

Mr Trump gave Mr Mattis six months to come up with a policy on those currently serving, and he must implement it by 23 March, 2018, the official said.

The controversial orders Donald Trump has already issued Show all 9 1 /9 The controversial orders Donald Trump has already issued The controversial orders Donald Trump has already issued Trump and the media White House Press Secretary Sean Spicer takes questions during the daily press briefing Getty Images The controversial orders Donald Trump has already issued Trump and the Trans-Pacific Partnership Union leaders applaud US President Donald Trump for signing an executive order withdrawing the US from the Trans-Pacific Partnership negotiations during a meeting in the Roosevelt Room of the White House in Washington DC. Mr Trump issued a presidential memorandum in January announcing that the US would withdraw from the trade deal Getty The controversial orders Donald Trump has already issued Trump and the Mexico wall A US Border Patrol vehicle sits waiting for illegal immigrants at a fence opening near the US-Mexico border near McAllen, Texas. The number of incoming immigrants has surged ahead of the upcoming Presidential inauguration of Donald Trump, who has pledged to build a wall along the US-Mexico border. A signature campaign promise, Mr Trump outlined his intention to build a border wall on the US-Mexico border days after taking office Getty Images The controversial orders Donald Trump has already issued Trump and abortion US President Donald Trump signs an executive order as Chief of Staff Reince Priebus looks on in the Oval Office of the White House. Mr Trump reinstated a ban on American financial aide being granted to non-governmental organizations that provide abortion counseling, provide abortion referrals, or advocate for abortion access outside of the United States Getty Images The controversial orders Donald Trump has already issued Trump and the Dakota Access pipeline Opponents of the Keystone XL and Dakota Access pipelines hold a rally as they protest US President Donald Trump's executive orders advancing their construction, at Columbus Circle in New York. US President Donald Trump signed executive orders reviving the construction of two controversial oil pipelines, but said the projects would be subject to renegotiation Getty Images The controversial orders Donald Trump has already issued Trump and 'Obamacare' Nancy Pelosi who is the minority leader of the House of Representatives speaks beside House Democrats at an event to protect the Affordable Care Act in Los Angeles, California. US President Donald Trump's effort to make good on his campaign promise to repeal and replace the healthcare law failed when Republicans failed to get enough votes. Mr Trump has promised to revisit the matter Getty Images The controversial orders Donald Trump has already issued Donald Trump and 'sanctuary cities' US President Donald Trump signed an executive order in January threatening to pull funding for so-called "sanctuary cities" if they do not comply with federal immigration law AP The controversial orders Donald Trump has already issued Trump and the travel ban US President Donald Trump has attempted twice to restrict travel into the United States from several predominantly Muslim countries. The first attempt, in February, was met with swift opposition from protesters who flocked to airports around the country. That travel ban was later blocked by the Ninth Circuit Court of Appeals. The second ban was blocked by a federal judge a day before it was scheduled to be implemented in mid-March SANDY HUFFAKER/AFP/Getty Images The controversial orders Donald Trump has already issued Trump and climate change US President Donald Trump sought to dismantle several of his predecessor's actions on climate change in March. His order instructed the Environmental Protection Agency to reevaluate the Clean Power Plan, which would cap power plant emissions Shannon Stapleton/Reuters

In a tweet last month, Mr Trump said the federal government “will not accept or allow” transgender individuals to serve “in any capacity” in the military.

The White House official said Mr Trump also directed Mr Mattis to halt the use of federal funds to pay for sexual reassignment surgeries and medications, except in cases where it is deemed necessary to protect the health of an individual who has already begun the transition. That policy is to be written within six months and implemented by 23 March.

The Pentagon had little to say on the subject Friday. Dana W White, the main spokeswoman for Mr Mattis, issued a two-sentence statement saying Mr Mattis had received White House guidance on transgender policy, adding, “More information will be forthcoming.”

Transgender military ban: Late night hosts take on Trump

Only one year ago, in June 2016, then-Defense Secretary Ash Carter announced that transgender individuals could serve openly for the first time. Prior to that, most transgender people in the military had been forced to keep their status secret to avoid being discharged; Mr Trump's order appears to have returned the military to that same situation.

Since Mr Carter's policy change, some troops — possibly a couple hundred — have openly declared their status as transgender individuals.

Carter also had given the military services until 1 July this year to present plans for allowing transgender individuals to join the military. Shortly before that date, Mr Mattis extended the study period to the end of this year. And shortly after that, Trump went to Twitter to announce a total ban, without having used the customary interagency policy process.

At the time of Trump's tweet, the Pentagon was not prepared to change its policy. A flurry of White House meetings ensued, with participation by representatives of the Defense Department, to translate Trump's announcement into guidance that could be implemented and would stand up to expected legal challenges.

Just last week, Mr Mattis suggested he was open to the possibility of allowing some transgender troops to remain in uniform.

“The policy is going to address whether or not transgenders can serve under what conditions, what medical support they require, how much time would they be perhaps non-deployable, leaving others to pick up their share of everything,” he said Aug. 14. “There's a host of issues. And I'm learning more about this than I ever thought I would. And it's obviously very complex, including the privacy issues, which we respect.”

Estimates of the number of transgender troops in the service vary widely. A Rand Corp. study said roughly 2,500 transgender personnel may be serving in active duty, and 1,500 in the reserves. It estimated only 30 to 130 active-duty troops out of a force of 1.3 million would seek transition-related health care each year. Costs could be $2.4 million to $8.4 million, it estimated.

Among those who have cheered Trump's tweet, Elaine Donnelly said the president is halting “a massive social experiment.”

“Expensive, lifelong hormone treatments and irreversible surgeries associated with gender dysphoria would negatively affect personal deployability and mission readiness, without resolving underlying psychological problems, including high risks of suicide,” said Ms Donnelly, president of the Center for Military Readiness.