Stronger fines and other enforcement would help, but the first thing is to make sure that you actually have accurate places to throw stuff out (or have the culture where people bring stuff with them and throw out at home, like some non-American countries). This article mentions how the streets got really bad during the pandemic when the city stopped doing certain things.
SF, NYC, and other cities with trash problems could significantly solve this just by having more trash and recycling cans and by changing them more often. You'll notice how much cleaner DC and its surrounding urban areas are than SF and NYC and that's because they have a bigger commitment to making it easy to not litter and they do more cleaning.