Yes but. I’ve called this a ‘yes but’ because you can compost some weeds, but you have to be careful. For example if you’ve got a patch of nettles, you can harvest the leaves and stems and put them in a compost heap. They are in fact a rich source of nutrients. However its best to keep the roots out, which may start to grow in your heap. This is true of the roots of many hard core perennial weeds. Some weeds, such as Japanese Knotweed, reproduce vegetatively – which means they sprout from a cutting (and in the case of Knotweed from the root as well) – and should be kept well away from a cool compost heap. You should also be careful putting weeds laden with seeds in a compost bin. Seeds can survive cool composting and come up in your veggie plot the following year.
There are alternative ways of composting difficult weeds. In his book Weeds: An Earth Friendly Guide to their Identification, Use and Control, John Walker suggests using an old potting compost bag, turning it inside out, puncturing it with holes and leaving it in a sunny place. He also suggests drowning perennial weeds in a bucket, where, starved of air, they turn into a slurry like liquid, which can then be poured onto the garden.