ThemeShaper Forums » Thematic

[closed]

Custom CSS function

(3 posts)
  • Started 3 years ago by oakview
  • Latest reply from floridastyle
  • This topic is not a support question
  1. oakview
    Member

    Dunno if this has been posted before, but I thought it useful enough to pass along this small function. I found the raw code on the 'Net and nade it into a function which I now incorporate in every Wordpress site I build. Allows you to specify custom CSS on a per post or page basis using the built-in Wordpress custom fields. Enter "css" (without the quotes" in the Name field and your custom CSS in the Value field. Wordpress will automatically apply the CSS.

    function my_custom_css() {
    global $post;
    $css_key = get_post_meta($post->ID, 'css', true);
    
    	if (!empty($css_key) && is_page()) {
    		echo '<style type="text/css" media="screen">'. get_post_meta($post->ID, 'css', true) . '</style>';
    	}
    }
    add_action('wp_head', 'my_custom_css');
    
    ?>

    Enjoy!

    Posted 3 years ago #
  2. very cool. will keep this in mind. i have also just started figuring out how to make meta boxes... so there is the potential to make it a box and not a custom field.

    Posted 3 years ago #
  3. very cool.

    Posted 3 years ago #

RSS feed for this topic

Topic Closed

This topic has been closed to new replies.