How To Embed Custom CSS In Your Single Posts With Custom Fields ?

If you like using custom CSS in your WordPress single posts using custom fields then you can easily do that reading this tutorial.

Step-1 Open your header.php and insert following code somewhere in between <head></head> tags:

<?php if (is_single()) {
$customstyle = get_post_meta($post->ID, ‘customstyle’, true);
if (!empty($customstyle)) { ?>
<style type=”text/css”>
<?php echo $customstyle; ?>
<style>
<?php }
} ?>

Step-2 Now you can add a custom field in each of your post with name customstyle and add the css codes there itself as shown in the following example:

Example for adding a certain image to have border:

#coolimageclass{border: 5px solid #ccc;}

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.