Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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

This comment has been minimized.

Copy link
Owner Author

freshyill commented Aug 17, 2011

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
You can’t perform that action at this time.