I code for 8+ hours regularly, but that means I'm on the computer for 10-12+ hours.

TLDR: coding != learning, coding for 4h = easy, learning for 4h = hard, take care of your body, delegate what you can, automate the rest, save your attention

By coding I mean: reading errors logs, stack overflow, and the actual code/test/debug loop.

I've got two jobs and a small side project, so here are my directives:
- minimize meetings and do quick syncs once a day, ask for priorities and responsibilities, make your own tasks, ignore the rest (all hands, HR bullshit, random groups, etc)
- get down to business, keep your main goals in mind, think of a solution, research the docs/snippets/common solutions and then jump to the code.
- have more then one context, I'm a sr devops, a sr data engineer and got a side project. Sometimes one job gets boring, and I'm excited about the other. I rarely get bored at both jobs at the same time. So I'm always motivated and never afraid of getting fired.
- This is the most important: stay healthy, walk, drink water, eat well. This will give you energy, repair some of your posture flaws and prevent your body from breaking down from such heavy workload.
- delegate mundane tasks: 2 incomes means, I don't cook, wash, clean, nothing.
- automate everything, make filters for your inbox, use a calendar to remind you of stuff,
- Attention+focus = gold, don't spend it on shit. silence notifications, uninstall social media, put you phone on do not disturb, silence all channels on slack, create alerts for keywords in slack for stuff you actually need to know. e.g: jenkins, your_name, project names

My time is spent as:

Mon-Fri
- exercise: 1hour
- job1: 4-6hours
- job2: 4-6hours
- sleep: 5-7hours
- food, drink, hygiene, general body maintenance: 2h
Sat-Sun:
- exercise: 1hour
- sleep: 8-10hours
- pick up some slack from the week, study something I need for work, work on one of my sideprojects: 2-3hours
- relax, fun, games: whatever is left

job1-job2: I start at 9:00 and I usually work until 22:00. That means I'm always on slack/teams and I do overlap the two jobs.

I make regular 10min breaks every 50-100min, and I stop for lunch (eat, power nap, back at it).

exercise: walking is fine, go to a gym if you can, don't overdo it so you can do it tomorrow.

sleep: I don't get sleep deprived but I do get tired by Friday, which makes the weekend so much more enjoyable

You can be productive all day, just like you can be a long distance runner, start small and keep progressing.
In you first days of running/programming/* you are mostly learning a bunch os stuff and figuring out the profession, yourself and your strengths and weaknesses. So it takes more energy because most of it is spent on learning about your trade and about you.

Know thyself. I like programming, I like math, I like learning, I like hard stuff. I'm not a design guy, I don't do UI, and I won't be a project manager. So I place myself in jobs/tasks/places I can maximize my output with minimal effort.

Doing a full day of devops is easy to me, but I'd cry after 2h coding a react app.
Devops I know, so it's more time outputting solutions and less time inputting knowledge. React, I've got to basically learn every step of the way, so it's 10 times more exhausting.

So, True, you can't be productive all day. But you can 100% go way above 4hours coding.