Most importantly make sure you are writing something you really care about (as long as we're not talking about your day-to-day job here). No hobby is made better by forcing yourself to do only what you think others will appreciate rather than what you truly love to create.
As for getting bored in the creative process, and this is just a personal annecdote, but I find that I am unable to really focus on writing or programming when I have been habitually inundating myself with easy stimuli. Things like using my phone too often, playing video games or binging on Netflix, all draw power from my ability to sit down and really pour myself into my true hobby.
Either way, if you find yourself not performing how you would like to, then that just means it's time to change something. So experiment with variables in your days' activities and see what gets that productivity churning!