Yes for most weeds, and this is one of the few cases where the caveat genuinely matters. Seed heads and persistent roots survive cold composting and you will replant them across the garden with your finished compost. Below: whether you can compost weeds, why, how much to add, and the mistakes that cause trouble.
Adding weeds to a pile. Chop it, mix it, bury it.
Why
Weeds are just plant material: nitrogen-rich when green, and they compost readily. The problem is not the foliage, it is the reproductive parts.
Many weed seeds need sustained temperatures above about 55°C to be killed. A cold pile never reaches that. Roots of bindweed, couch grass, ground elder and horsetail can regenerate from fragments.
How to add it
Leafy annual weeds, no seed heads: straight in, no thought required.
Seeding weeds: only in a genuinely hot pile, turned so the outside moves to the middle.
Persistent perennial roots: drown them in a bucket of water for several weeks first, until they are unrecognisable sludge, then compost the lot. Or dry them to a crisp on concrete.
Common mistakes
Trusting a pile that was hot once. The outside of a hot pile never reaches core temperature unless you turn it.
Composting seed heads in a cold heap and then wondering why the weeds got worse.