Short answer
Yes. Some British and Commonwealth soldiers were executed by firing squad for desertion during the First World War. Desertion was the most common charge among the men executed. Most soldiers sentenced to death, however, were never shot. Their sentences were commuted to lighter punishments.
How many were executed
Figures vary a little between sources. Historians commonly cite a total of around 350 British and Commonwealth soldiers executed for military offenses during the war. Several thousand death sentences were handed down in total, so the large majority were not carried out.
Each death sentence had to be confirmed by senior commanders, including the British commander-in-chief in France. Confirmation was not automatic, and a sentence could be reduced at any stage.
Why soldiers were shot for desertion
Military law at the time allowed death as a punishment for desertion in wartime. Commanders saw executions as a warning to others, especially when units had suffered heavy losses and discipline was under strain.
Courts-martial were often short. The accused usually had limited legal help and few chances to present a defense or appeal. Historians have pointed to these factors when they argue that the process was unfair.
Shell shock and the men who were executed
Many of the men executed had spent long periods in combat. Some showed symptoms that doctors now associate with shell shock, or post-traumatic stress. At the time, medical understanding was limited, and those symptoms were not always taken into account at trial.
Campaigners and later historians have argued that some of the executions were unjust for this reason. The issue remains debated.
The 2006 pardon
In 2006, the UK Parliament granted a blanket pardon to British soldiers executed for offenses such as desertion during the First World War. The pardon was a formal recognition of the injustice many people saw in these cases.
How this compares with the Second World War
Far fewer British soldiers were executed in the Second World War than in the First. Desertion was still punished, but outcomes were more often prison sentences or discharge than a firing squad. For the Second World War picture, see the ww2 deserters uk overview.
Where the records are
The National Archives at Kew holds many First World War court-martial and personnel records. Some files are available to view online, and others need to be requested. Check the catalogue before ordering a file, since access rules vary.