Whenever mounting shelves in a closet I would recommend the following:
- Determine what is behind the wall you are mounting to. Is there any electrical, plumbing, or ducting to worry about? Don't just assume on this. Actually check as if there is something and you didn't check you could seriously injure or kill yourself (if electrical).
- Determine where studs are with stud finder. If none are found within span you are mounting shelf, there are almost always at least two on the corners of the room.
- If studs are found, try to anchor as much as you can directly to the studs. I know that often the studs aren't in the optimal placement for a shelf but you get the most secure mount for "free" as the support already exists.
- For those mounts that you can't find a stud for, then uses drywall anchors. For these you will need to estimate how much load you expect to be on them. If your shelf has a support touching the ground (most weight is not on the wall) then less than pretty low weight rated ones are perfectly fine. If it is a floating shelf then calculate the weight of the shelf + the most weight you would ever put on it and divide by the number of mount points to determine your weight requirement per drywall anchor.