The decline of open habitats in Europe, such as semi-natural grasslands and heathlands, has caused a general decline in biodiversity, which has been well documented for butterflies. Current conservation practices often involve grazing by domestic livestock to maintain suitable butterfly habitats. The extent to which wild ungulates may play a similar role remains largely unknown. Through their rooting activity, wild boar could be effective to reduce grass encroachment and restore pioneer microhabitats that are vital to many grassland insects in temperate climates. Here, we assessed the microhabitat requirements of Pyrgus malvae, an endangered butterfly of heathland and grassland habitats in the Netherlands, with special attention for the influence of wild boar rooting. To date, oviposition site selection of this species has concentrated on calcareous grasslands, whereas we also include heathlands. Overall, larval occupancy was higher in warm, open and sparsely vegetated microhabitats, which supports earlier findings. In heathland, microhabitat occupancy was positively affected by bryophyte and litter cover. In heath-grassland mosaic, microhabitat occupancy was also influenced by bryophyte and litter cover, but in addition low grass cover increased occupancy by favouring host plants. In grassland, only low grass cover and host plant cover determined microhabitat quality. Across all habitats, occupied microhabitats were characterized by lower vegetation as well as higher average daytime temperatures than unoccupied microhabitats. We discovered that wild boar play an important role in reducing grass cover by shallow rooting in grass patches, thereby increasing host plant availability. Hence, wild boar may have an added value in maintaining and restoring P. malvae microhabitats in grassland habitats in addition to grazing by domestic livestock.