The shape of the wires that make the magnetic fields can be altered, which will alter the overall shape of the field itself. Also, magnetic fields can press against each other and will be shaped accordingly. There are some other ways i believe too, but I can't remember them.
The classic solution, IIRC, is to use 'field poles' ie cones or pyramids of high permeability material such as 'soft iron', to 'focus', 'concentrate' or otherwise shape the magnetic field of a magnet. Modern manufacturing techniques allow a magnet or an electromagnet's core to be custom shaped. Uh, some cores may be laminated to suppress losses due to eddy currents...
If you stack bar magnets together and restrain them against mutual attraction / repulsion, you can get interesting magnetic fields. A version of this is seen in eg fridge magnets that have little apparent field on one side...
Also keep in mind that you're not really "shaping" a magnetic field, what you are doing is combining fields (superposition) that allows the net field to take effect.
The field due to each element is still the same, and the net field still has the same properties, i.e. it has a vector potential, hence it is divergence free since curl(div F) = 0
and the sum of two fields satisfy this too since curl (F+G) = curl F + curl G