Embed Custom CSS Styles

Discussion in 'WordPress' started by lordoracle, Apr 17, 2012.

  1. #1
    Posts sometimes require additional CSS styling. Sure, you can switch WordPress’ editor to HTML mode and add inline styling to your post’s content. But even when inline styling is useful, it isn’t always the cleanest solution.

    With custom fields, we can easily create new CSS classes for individual posts and make WordPress automatically add them to the blog’s header.

    Open your header.php file and insert the following code between the <head> and </head> HTML tags:


    <?php if (is_single()) {$css = get_post_meta($post->ID, 'css', true);if (!empty($css)) { ?><style type="text/css"><?php echo $css; ?><style><?php }} ?>
    
    PHP:
    Now, when you write a post or page that requires custom CSS styling, just create a custom field called css and paste in your custom CSS styling as the value. As simple as that!
     
    lordoracle, Apr 17, 2012 IP
  2. mmedia

    mmedia Guest

    Messages:
    38
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    that is a good idea i used until now "WP Post Styling" plugin but next time I have extra time I'm going to implement your idea!

    thanks
     
    mmedia, Apr 18, 2012 IP