Skip Navigation

[Résolu] Set Div body class with custom field

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

This topic contains 2 réponses, has 2 voix.

Last updated by seanN-5 Il y a 1 an et 8 mois.

Assigned support staff: Luo Yang.


I am trying to add a class to a <div> using a custom field.

Here is the code I am trying:

<div class="[wpv-post-field name='performance-ed-class']">[types field="end-date"][/types]</div>

This is what I am getting... no class added: <div class="">September 4, 2019</div>


Luo Yang

Languages: Anglais (English ) Chinois simplifié (简体中文 )

Timezone: Asia/Hong_Kong (GMT+08:00)


I assume the custom field "performance-ed-class" is created with Types plugin, Types will add pre-fix "wpcf-" before the field slug, so you can modify your codes as below:

<div class="[wpv-post-field name='wpcf-performance-ed-class']">[types field="end-date"][/types]</div>

And test again


My issue is resolved now. Thank you!

Luo, thanks for the fast response. I found another solution to what I was trying to do (hide a field is a certain post type). I wound up using the conditional logic to say if is post type A then hide. I'm going to duplicate the view and try your solution as well.