Two possibilities immediately come to mind...
rabble-rouser (Cambridge Dictionary)
a person who says, writes, or does things that make crowds of people excited or angry, usually intentionally in order to make them act in a particular way
populist (Cambridge Dictionary)
trying to be popular with ordinary people and to represent their ideas and opinions
Note that rabble-rouser is much more informal, and is always pejorative, but populist is sometimes (though not often) used approvingly, and it can appear in quite formal contexts.
There are also lots of pejorative terms specifically relevant to politicians who will endorse anything if they think it will win votes - political opportunist, windsock, weathercock, chameleon,...