The key is to know how much you can substitute. Replace up to half of the flour the recipe calls for with finely ground nuts when baking. If you do any more than that, the final product will not hold together very well. But you're okay if you stick to up to half of the flour amount.
Here's a substitution sample with pistachio cake:
I decided I wanted to make a pistachio-flavored cake—one with an authentic pistachio flavor. Looking at the recipe, I found that it called for 1 3/4 cups of cake flour.
I calculated that I could use up to 7/8 of a cup of ground pistachios. I decided to go with 1/2 a cup so that the flavor would be just slightly nutty.
...So I shelled a bunch of pistachios, put them through a food processor, and voila! A tasty flour substitute. I then proceeded to use just 1 1/4 cups of flour instead of 1 3/4 cups.
Happy baking, friends!