Page-specific CSS and Javascript using Wordpress Custom Fields
Use this PHP snippet and Wordpress custom fields to reference page-specific CSS and Javascript files in your Wordpress theme.
DLB's latest project is a website with some content-complexity, using Wordpress as a Content Management System. Wordpress is functional as a custom CMS largely because of Custom Fields, which allow you to assign an arbitrary amount of meta-data to a post (the core element of a Wordpress site).
Now, on this website, it came about that some of the pages needed specific Javascript classes and methods, and even more than that needed custom CSS classes.
Immediately, it occurred to me that this could be handled through custom fields. So, what I did, and you can do, too, is create two custom fields: one called custom_css and one called custom_js.
With this accomplished, edit your Wordpress theme's header.php, and write a couple little PHP conditionals to check for this field. Or else, just copy and paste mine!
| Tagged with: | Content Management Systems, CSS, Javascript, PHP, Web Design, Wordpress |




