Home / css / Custom CSS per post
  • How to Custom CSS per post

    no thumbnail sorry: 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.

    wordpress snippet : PHP

    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');

    ( WordPress codex functions, hooks, in this snippet. )

    template, stylesheet, bloginfo, wp_head, is_single, add_action, _e, _ex, get_bloginfo, wp,