wordpress snippets last updated   : January 29, 2015
we now have 646 snippets

Custom CSS per post

wordpress snippet

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.

snippet :  PHPcopy
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');
source →

Did you like this post? If so please share it with your friends. Thanks!