According to Lizzie Post, coauthor of Emily Post's Etiquette, 18th edition:
When you RSVP for a party, let the host know your dietary needs, clearly but nicely. Say something like, "We're so happy to come Friday night -- I do want to let you know that I'm a vegetarian, and I'm more than happy to bring a dish." If you're already at the party, you can say to the host, "Becky, I have a food allergy -- can you tell me which dishes contain wheat?" Don't make a big fuss; just quietly ask. If you don't get a chance to speak with the host, it is fine to refuse a dish and say, "I'm sorry I didn't let you know ahead of time."
When you're the one extending an invitation, check in with guests before the party and ask if they have any food allergies -- or even if there's anything they truly don't like to eat. That gives them a chance to say, "I really can't handle cilantro -- but other than that, I'm good to go!" Having a buffet? Consider using place cards to write the name of the dish and what the ingredients are. You don't have to do this, but in this day and age, people appreciate it.