The idea of the heroic king fighting on the frontlines is a giant load of bullshit that was (and still is) used to manipulate the masses.
Not entirely bullshit. Leaders like Alexander the Great and King Richard I are noted as being constantly in the thick of the fighting. Warlords like that need to be in the fighting, exposed to danger, in order to preserve their own military credentials with their troops (who will be far less fooled by tall tales of battles they themselves were in). And that kind of warlord leadership is pretty common before the modern day.
The thing is, it’s ineffective, because it means every time you fight a battle, you risk a decapitation of your entire army or state and a succession crisis. So military institutions that last long enough pretty inevitably come to the conclusion that “At least out of javelin range” is the preferred distance for a king or general.