Skip to content

Instantly share code, notes, and snippets.

@jcsrb
Created January 15, 2012 14:46
Show Gist options
  • Select an option

  • Save jcsrb/1616065 to your computer and use it in GitHub Desktop.

Select an option

Save jcsrb/1616065 to your computer and use it in GitHub Desktop.
Wordpress Custom Class for Post
<?php
/*
Plugin Name: Custom Post Class
Description: add a custom class to your post, use 'post-class' as custom field
Version: 1.0
Author: Jakob Cosoroaba
Author URI: http://jakob.cosoroaba.ro/
*/
function extra_post_class($classes) {
global $post;
$classes[] = get_post_meta($post->ID, 'post-class', true);
return $classes;
}
add_filter('post_class', 'extra_post_class');
?>
article.light-grey .more-link{ background-color: #eee;}
article.yellow .more-link{ background-color: #fc6;}
article.red .more-link{ background-color: #f66;}
article.blue .more-link{ background-color: #6cf;}
article.dark-grey .more-link{ background-color: #555;}

Install as usual

Activate Custom Fields

Activate Custom Fields

Add post-class custom field

Add post-class custom field

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