Is it true that not all generic lens hoods work on all lenses (provided the filter diameter matches, of course)? I read that the focal length plays a role in it - but I cannot find such readings on any lens hoods I see available online.
Most lenses from the major manufacturers have a proprietary connector that the hood uses to attach to the front of the lens. While you can purchase hoods that attach to filter threads, that doesn't guarantee the hood will work properly with a lens it can screw onto. This is because:
I read that the focal length plays a role...
It's even more involved than that: focal length plus sensor size play a role since ultimately it is about the angle of view. This distinction is most often applied to telephoto lenses, which yield a fairly narrow angle of view. There are a few cases of lenses that have two different hoods available: one for the wider angle of view yielded with a larger (typically FF sensor) and another for the narrower angle of view yielded with a smaller (typically APS-C) sensor.
If you want to have some fun with this concept, try printing and constructing a paper/cardboard lens hood for your lens from lenshood.net which will be for use on APS-C cameras and another hood for the same lens from lenshood.co.uk that will be the correct size for that lens when mounted on a Full Frame camera. Then compare the two hoods. If you use the hood designed for the crop body on the FF camera, you will see vignetting as a result of the hood blocking some of the light that would wind up in the part of the image circle cast by the lens that falls on a FF sensor but that does not fall on an APS-C sensor.
If you want to go the economical route, you're probably better off buying a third party hood made to fit to a particular lens, such as this one for under $10 meant to replace the OEM ET-87 from Canon that runs about $60. There are also a variety of other third party ET-87 copies available at various prices and quality levels. Other hoods for other lenses have a similar variety of options out there as well.
It's also not just focal length that pays a role in hood design. If the front of the lens rotates during focusing or zooming, a circular hood should be used that is as short as the shortest corner of a tulip-shaped hood for a lens with the same angle of view and front element size and position.
It just happens that I made some test shots from another question which demonstrate this perfectly. I happen to have two Fujifilm lenses which have the same filter diameter and same bayonet hood mount — 23mm and 56mm. I took two test shots with the 23mm at the widest aperture (f/1.4), the first with the correct hood and the second with the 56mm's hood. The result is obvious in the corners.
I didn't take an example showing this, but if you stop down to f/16, the hood is even more apparent — you can see the perfect circle. That may seem counterintuitive, as reviews like this one often show vignetting dropping off as you stop down, but in this case, what's happening is the obstruction is simply in sharper focus.
Also, consider the case of a zoom lens — the hood doesn't (in any instance I'm aware of!) change, which means that the shade provided at the long end must be the same as the first, so it can't be as complete. For example, if this were a 23mm-56mm zoom lens, it would normally be matched to a filter designed for 23mm.
I read that the focal length plays a role in it
Think what would happen if you put a lens hood meant for a telephoto on a wide angle lens: all your photos would include a lot of that lens hood. Wide angle lens hoods are much shorter than hoods meant for longer lenses specifically to avoid this problem.
Is it true that not all generic lens hoods work on all lenses (provided the filter diameter matches, of course)?
Yes, it's true for the reason explained above, but also because different lenses may have different hood attachment mechanisms. Canon and Nikon lenses, for example, each have bayonet-style mounts for their hoods.
There are generic "universal" hoods, often made of rubber, that are either friction fit onto the end of the lens or attached to the filter threads. You do still need to be aware of the focal length issue so that you don't end up with a hood that's too long and thus causes vignetting.
It's even worse than that. Equivalent focal length (focal length times crop factor) tells you the viewing angle of your camera at a large distance. It does not tell you where it starts. The camera has an entrance pupil with the diameter f/aperture (with f not being the equivalent but the real focal length), being the aperture how it appears to be sized and located when looking into the front lens, and each point of that entrance pupil should be able to see the entire scene or you get vignetting (and/or cat eyes' bokeh which it turns out that some particular lenses even have before attaching a lens hood). So how far from the front lens is that entrance pupil from which you need to measure the angle dictated by equivalent focal length?
That's not discernible from the camera specs but depends on the particular lens recipe used for constructing the camera. Also it depends on the zoom factor, again in a manner specific to the lens recipe and construction.