When you shoot into the sun, lens flare is unavoidable. If the ball of the sun is outside the composition, flare can be avoided by using a lens hood or even your hand. I've used my hand to eliminate lens flare for decades. However, if the sun is included in the frame, as in this picture of Quiver trees at sunset in Namibia, there is nothing you can do to get rid of it at the time of shooting. Only in post-processing can it be cloned out.
Some flare is objectionable, and some is not. In this picture, I like the rays of light emanating from the sun, but in each of the lower corners, there is a curved red line that is a type of lens flare and, in my opinion, it needs to be cloned out.
My settings for this picture were 1/25, f/13, 200 ISO, 24mm wide angle lens. I used a tripod.