Preheat oven to 350°F (175°C). Position rack in center.
Grease two 8-inch round cake pans and line bottoms with parchment paper.
In a medium bowl, whisk together flour, xanthan gum (if using), baking powder, baking soda, and salt.
In a large mixing bowl, cream softened butter until smooth (about 1 minute).
Gradually add sugar and beat until light and fluffy (3-4 minutes).
Add eggs one at a time, beating well after each addition.
Mix in vanilla extract.
Gradually add dry ingredients alternating with milk, beginning and ending with flour mixture (3 flour additions, 2 milk additions).
Fold in melted coconut oil until just combined.
Divide batter evenly between prepared pans.
Bake for 30-35 minutes or until a toothpick inserted comes out clean.
Cool in pans for 10 minutes, then remove to wire racks to cool completely.