I'd echo all the advice about good nutrition & rest, and about being careful with caffeine dependence.
Another thing that I've found helpful is starting the day with tasks that make it "easy" to find a groove. For example, I might stop a task partially completed the night before and leave myself some good WIP/TODO comments: that lets me begin the next day in a clear starting place. Or I might begin a day with really clearly defined tasks: code reviews, or a ticket/task that's short and clear, whatever task is an "easy win" for you. Starting the day with an immediate sense of accomplishment helps me avoid stalling out before I get into the day's work.
One other idea is, not everyone's prime productivity hours are the same. Some people feel stuck/unmotivated from 8-noon, but find it really easy to focus between 2-10pm; others can work hard at 6am but lose energy by 2pm. If your job lets you match your working hours to the times when you're personally at your best, that can be a huge help.
We're a place where coders share, stay up-to-date and grow their careers.
We strive for transparency and don't collect excess data.