Created
August 17, 2011 05:36
-
-
Save freshyill/1150874 to your computer and use it in GitHub Desktop.
Add a custom post class in WordPress
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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(); ?>"> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is the first time I've created a gist, so I hope I didn't do anything stupid.