Skip to content

Instantly share code, notes, and snippets.

@freshyill
Created August 17, 2011 05:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save freshyill/1150874 to your computer and use it in GitHub Desktop.
Save freshyill/1150874 to your computer and use it in GitHub Desktop.
Add a custom post class in WordPress
<?php // First, create a custom field named 'custom_class' in WordPress and give it a value ?>
<?php // The Loop...
if (have_posts()) : ?>
<?php while (have_posts()) : the_post(); ?>
<?php // Declare a variable using the custom field
$custom_classes = get_post_meta($post->ID, 'custom_class', false); ?>
<?php // Use the variable in the post class ?>
<article <?php post_class($custom_classes) ?> id="post-<?php the_ID(); ?>">
@freshyill
Copy link
Author

This is the first time I've created a gist, so I hope I didn't do anything stupid.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment