If code has a licence that allows sharing of modifications, is it possible to prevent it being hosted on a site that uses third party advertising? Do licences with this intent exist, or is it not possible to prevent advertising without losing the ability to share modifications?
Maybe such a license exists. But it would not be an Free Software or Open Source license. A FLOSS license must not discriminate or forbid any form of usage. That includes the way in which the software is distributed.
The question of making or sharing modifications is conceptually unrelated to the question of usage restrictions.