Here is a tutorial using a router-cut "Side Cleat Groove" and matching wall bracket.
Side Cleat Groove – After the shelf is dry, a few passes on the router table will leave you with a groove to accept the side bracket.
Next, cut the stopped groove in the same divider using a 1" ...
If you could put 1/4" plywood on each side, then there are lots of shelf supports that would work for you. See Lee Valley hidden shelf support or flipper shelf support or spring shelf support. They are in the process of changing their website, so they don't currently show how these are used, but if you download their catalog or use their app to download the ...
Magnetically driven fasteners are one method
I've never never used them and I think they are crazy expensive, but they are aimed at this niche.
Another way would be to route a slot in the ends of the shelf from the back to almost the front and then fit a matching ledge to the wall at each end.
Edit: I didn't read the requirement that it be supported on the ends.
The easiest way to support it from the ends would be with z-clips
But they are 2 1/8 wide which is likely too wide.
Tiberhan clips appear to be smaller. You may be able to recess it into the end of the board to reduce the gap between it and the wall. https://www.amazon.com/Bracket-...