Month: January 2015

Post-specific Javascript and CSS in WordPress

A couple of recent posts here — An oscillator from a jam-jar lid The value of a second opinion — required some post-specific Javascript and CSS styling. It took me a little while to figure out how to achieve this, given my limited exposure to PHP in general and WordPress programming in particular. This is how I went about it; there may well be better ways. Start writing post At this point your draft is assigned a post-ID. This is the value at the end of the post’s URL. For example, this post has URL https://redfrontdoor.org/blog/?p=970 and its post-ID is 970. Write post-specific Javascript Make a self-contained Javascript file, wrapping the logic in jQuery(document).ready(function($) { // [… code goes here

Continue reading