How to Insert Css into WordPress Post

Jun 18, 2012, by admin

Insert Css into WordPress PostEvery now and then, a particular post needs to be styled with some custom css styles. Sure, you can directly insert CSS in your post, but that not very clean. In this post, I’m going to show you how to insert css in a easy way, by using a custom field.

Note: This tutorial helps in answering the following questions

How to Insert Css into WordPress Post , how to add custom css in wordpress , how to add css file in wordpress , how to add css file in wordpress , how to include external css in wordpress

 

First, 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 }

} ?>

Once done, when you’re writing a post or page which require some custom css styling, you’ll just have to create a custom field named css and paste your custom css styles as a value. That’s simple as that!