ExtreaHead plugin for Wordpress
The ExtraHead plugin makes it easy to insert arbitrary code into the header of any page on a per-page basis. Just create a custom field with the key “extreahead” and the value will be inserted, untouched, into the header.
Sometimes you just want a little custom CSS or javascript on a page.
I was a bit surprised that nothing like this was easily found on the Wordpress codex or via Google, so I took an existing plugin (HeadMeta) and tweaked it to my needs.
The plugin is absurdly simple, in fact it consists of one file:
< ?
function extrahead() {
global $posts;
// only act when viewing a single post or a page. Else, exit.
if ( !(is_single() || is_page() ) ) return;
// Get the post
$post = $posts[0];
// Get the keys and values of the custom fields:
$id = $post->ID;
$data = get_post_meta($id, 'extrahead', false);
if (is_array($data)) {
print "\n";
foreach ($data as $line) {
print "$line\n";
}
print "\n";
}
}
// Hook into the Plugin API
add_action('wp_head', 'extrahead');
?>