Managers help organize their teams to be effective by hiring people with complimentary strengths, insulating them from distractions, and representing their team's work and achievements to leadership.
Managers unblock their team and get out of the way.
If a manager is writing code, they are not managing - they are developing. If there's not enough developers, they should be hiring.
And directors...they should definitely not be writing code.
The only valid example I've seen for leadership writing code is when they are acting as a customer and consuming their team's product (e.g. their team owns a service) with toy applications so they can understand the customer experience.