Custom CSS per post

Great snippet from digwp.com this will use a specified CSS file based on post ID. Create a new directory within your theme called art-direction then create a new css file for the specified post in this format style-0000.css where 000 is the post ID.

 

 

function artStyle() {
global $post;
if (is_single()) {
$currentID = $post->ID;
$serverfilepath = TEMPLATEPATH.'/art-direction/style-'.$currentID.'.css';
$publicfilepath = get_bloginfo('template_url');
$publicfilepath .= '/art-direction/style-'.$currentID.'.css';
if (file_exists($serverfilepath)) {
echo "<link rel='stylesheet' type=text/css' href='$publicfilepath' media='screen' />"."n";
}
}
}
add_action('wp_head', 'artStyle');

Be Sociable, Share!

Leave a comment