Last week I was creating a landing page for a client. I didn’t develop the site so I wasn’t very familiar with the way the theme was coded and didn’t want to make any risky changes. I decided to create a new page template and assigned it as the template to the landing page. This isolated my changes from the rest of the theme.
When I looked at the generated html code and saw that the active plugins added a number of stylesheets that the landing page did not need. To speed up the loading time of the page (which is important for first impressions), I decided to remove all the unnecessary ones.
I noticed that each of the statements had an ‘id‘ that ended in ‘-css.’
Removing the ‘-css‘ suffix was much easier and quicker than searching the all the plugins for wp_enqueue_syle() calls to discover the handles.
The code to dequeue these stylesheets was easy:
The priority for the add_action() call had to be high enough to ensure that all the plugins were done with their wp_enqueue_style() calls.
I put this code in the landing page template file so that it is only called for pages using that template file.
While it would be better that these plugins did not run at all on this page, achieving that is much more complicated.