Blogless: Blog of Design Less Better.

Posts tagged .

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.

Setting up the custom fields in Wordpress
Put the fully qualified URI of the file into a custom field.

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!

These icons link to social bookmarking sites where readers can share and discover new web pages.
PaulAug 11, 2008
 

Making the reCAPTCHA Wordpress Plugin Validate

If you are like us, you want to harness the awesome power of reCAPTCHA for your Wordpress blog and you also want valid XHTML. Before now, this was impossible. DLB is pleased to offer you a fix, and continue doing our bit to make the web a more standardized place.

Background

reCAPTCHA is a free CAPTCHA service that helps to digitize books.

A CAPTCHA is a program that can tell whether its user is a human or a computer, by asking the user to copy some distorted text. You've probably seen them, either here, or elsewhere on the web. If not, just click here for an example.

Reading Spidey
The Internet Archive is going to help Spidey enter "the digital age".

reCAPTCHA gets these words from books that the Internet Archive is digitizing. Digitizing books is done by photographically scanning the book's pages, and then transforming these scans into text using "Optical Character Recognition" (OCR).

All this together means that when you leave a comment, in addition to contributing to the discussion, you are both proving you are a person, not a spambot, and helping humanity's effort to archive it's knowledge digitally.

The Problem

Which is all milk and honey, but there's a problem. As good citizens of the web, and as Wordpress users, BlogLESS utilizes reCAPTCHA's handy Wordpress Plugin. But, as good citizens, BlogLESS is further committed to web standards. This means that all our HTML and CSS needs to be valid. Unfortunately, the Wordpress reCAPTCHA plugin doesn't validate XHTML out of the box. (As it turns out, this is not its fault. It actually can't validate out of the box, which we'll see.)

The good news is, the fix is easy, once you understand the problem. You don't need to be a pro to make your Wordpress comments template valid again.

These icons link to social bookmarking sites where readers can share and discover new web pages.
PaulJul 21, 2008
 
Close this
E-mail It