Custom CSS Per Post


/ Published in: PHP
Save to your folder(s)

To use it, simply create a new folder called “art-direction” in your theme. Then to style any particular Post or Page, just drop a file in that folder named style-XXXX.css where XXXX is the ID of the Post or Page. When that Post or Page loads, WordPress will look for a file of that name. If it exists, it will load in in the head section.


Copy this code and paste it in your HTML
  1. function artStyle() {
  2. global $post;
  3. if (is_single()) {
  4. $currentID = $post->ID;
  5. $serverfilepath = TEMPLATEPATH.'/art-direction/style-'.$currentID.'.css';
  6. $publicfilepath = get_bloginfo('template_url');
  7. $publicfilepath .= '/art-direction/style-'.$currentID.'.css';
  8. if (file_exists($serverfilepath)) {
  9. echo "<link rel='stylesheet' type=text/css' href='$publicfilepath' media='screen' />"."\n";
  10. }
  11. }
  12. }
  13. add_action('wp_head', 'artStyle');

URL: http://digwp.com/2010/02/custom-css-per-post

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.