Avatar of dirkil2
dirkil2
 asked on

How to style custom meta boxes with cmb2?

Hi!

I am fairly new to wordpress and I am using custom meta boxes. I really like the cmb2 plugin to help with creating custom meta boxes but I am wondering how to layout the fields in my meta boxes since I don't want them to be put in a straight list.

Since the generated output has lots of css classes attached I reckon that I am supposed to override the css as my needs dictate. That would be fine if I knew where to put my css. I don't suppose I should edit cmb2.css directly.

Can someone please explain to me what is the preferred way to add my css so that it is picked up in my custom meta boxes?

Regards,
Dirk.
WordPress

Avatar of undefined
Last Comment
dirkil2

8/22/2022 - Mon
Alicia St Rose

Hi Dirk,
Can you provide a link to the plugin you are using?
dirkil2

ASKER
Sure, I can. I must have forgotten this in the first place.

CMB2 Plugin
ASKER CERTIFIED SOLUTION
Alicia St Rose

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
dirkil2

ASKER
Perfect! Is there also a way how to link in a css file instead of single css lines? The problem is where to put that css file and how to get the path correct in the <link> statement.
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes
Alicia St Rose

The plugin's css is already added to the head when the plugin is activated. If you want to override the styles you'll need to add styles in the head with the code as demonstrated in my answer.

Otherwise, you will have to dequeue the plugin styles and enqueue your own stylesheet. You will conditionally target the admin with "if(is_admin)".
dirkil2

ASKER
Thank you very mch for your help.