Link to home
Start Free TrialLog in
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.
Avatar of Alicia St Rose
Alicia St Rose
Flag of United States of America image

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

ASKER

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

CMB2 Plugin
ASKER CERTIFIED SOLUTION
Avatar of Alicia St Rose
Alicia St Rose
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of 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.
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)".
Avatar of dirkil2

ASKER

Thank you very mch for your help.