Elephants play a crucial role in seed dispersal within their habitats by consuming a variety of fruits and plants. After digesting the seeds, they excrete them in a different location as they move around, helping the seeds to spread and germinate in new areas. This process aids in the regeneration and diversity of plant species within the ecosystem.