Scripts and stylesheets in WordPress sites

Published 2015-12-23 category: thoughts

WordPress is used by many different audiences. It is used by people who do not know much about code, as well as by experienced programmers1. Expectations of plug-ins therefore vary.

Some want plug-ins to automatically do everything. If they use a plug-in to integrate their Twitter stream into WordPress, they expect the plug-in to not only pull tweets from the Twitter API, they also want the necessary mark-up and CSS to display tweets in the front-end. Others will only expect a plug-in to do a specific task, leave front-end hooks for developers to output data surrounded by their own mark-up, styled by their own CSS and made interactive with their own scripts.

My ideal WordPress plug-in is of the latter type. I write my own templates (mark-up, stylesheet and scripts). Then, in the mark-up, I simply replace all dummy strings of text with template tags. My ideal Twitter plug-in, for example, would take care of fetching tweets from Twitters API, and it would then expose an API to output tweet data (the tweet itself, its date, its author, avatars etc), allowing a developer to output the relevant strings of text where required.

When I add a new plug-in (or a client requests one to be installed), I have made it a habit to make sure it does not add any CSS or JavaScript (plug-ins can add assets through wp_head() and wp_footer()). If it does, I usually undo the behaviour and add CSS or script to fit within the existing code.

1 And some experienced programmers will never touch WordPress (different discussion)

Comments, likes & shares

No webmentions about this post yet!