I have an situation: I just can't figure out how to add classes to some meta boxes.
I read these post from here, I tried this solution, but it did not work as I wanted. Is there a way to add classes (to customize them in CSS) to meta boxes?
For example in this case:

    'label' => 'a name',
    'desc'  => 'description',
    'id' => 'id_x',
    'type' => 'select',
    'options' => array('Bad', 'Good', 'Excellent'), /* HERE I WANT A CLASS FOR EACH THIS GUYS (to customize them in CSS) */
    'std' => "

I want that the HTML to look like this:

<span class="bad">Bad</span>
<span class="good">Good</span>
<span class="excellent">Excellent</span>

1 Answer 1


Answer given in your link is perfectly correct, you set it this way :

add_filter( 'postbox_classes_{post_type_name}_{metabox_id}', 'add_metabox_classes'  );

function add_metabox_classes($classes) {
  return $classes;
  • So, I must add this filter in "function.php" and change this: "post_type_name" and "metabox_id", right? Just all?
    – Blanka
    Aug 29, 2013 at 13:34
  • and 'another class' to your class too.
    – JMau
    Aug 29, 2013 at 14:39
  • How should be 'another_class'? I do not know what to write in "another_class". Can you be more specific, please?
    – Blanka
    Aug 29, 2013 at 15:13
  • If you want to use CSS class, replace your_class with your custom class and then style it.
    – JMau
    Aug 29, 2013 at 15:37
  • {post_type_name} and {metabox_id} are example values, use the actual values in their place.. (without the curly quotes).
    – t31os
    Aug 29, 2013 at 18:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.