The order of films is based on the timeline of events that take place within the universe, not in order of release date.
Remember the opening scene in Shrek where he's taking a bath in the swap and let's one rip? And all the fish float to the top ...
It's a little hard to believe that we're not far away from the 25th anniversary of the first Shrek film – but if that makes you feel a little old, at least there's some good news to cheer you up.