There are many options, depending on the design will be the best for your case, you may want to design (at least a basic) state machine to simplify the transition process (in general, restricted to the jumping/falling state).
Some ideas:
Areas on the ledge that allow the player to be on a ledge-grab-possible state.
Detect side collisions while jumping, then check if is a ledge (maybe with a raycast?).
If game is not tiled/grid, use ledge-grab-capable blocks (with special group/collision layer).
If tiled, name your tiles with a unique string, create an array of ledge index to identify ledges or make a tile/gridmap only for ledges.