Posted By

gd6d on 02/09/10


Tagged

css post wordpress


Versions (?)

Who likes this?

3 people have marked this snippet as a favorite

olen
BrianCoyDesign
mikoli


Custom CSS Per Post


 / Published in: PHP
 

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

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.

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

Report this snippet  

You need to login to post a comment.