Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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:

  array(
    '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>
share|improve this question
add comment

1 Answer

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) {
  array_push($classes,'your_class');
  return $classes;
}
share|improve this answer
    
So, I must add this filter in "function.php" and change this: "post_type_name" and "metabox_id", right? Just all? –  Blanka Aug 29 '13 at 13:34
    
and 'another class' to your class too. –  JMau Aug 29 '13 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 '13 at 15:13
    
If you want to use CSS class, replace your_class with your custom class and then style it. –  JMau Aug 29 '13 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 '13 at 18:38
show 1 more comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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