Home Forums General Issues Add Field Values to WordPress post_class Reply To: Add Field Values to WordPress post_class

  • Hey Michael,

    I think i indicated a wrong syntax in my first reply (my bad!)

    Please, try with this snippet :

    <?php $field = get_field(‘field_name’); ?>
    <article id=”post-<?php the_ID(); ?>” <?php post_class(‘et_pb_post clearfix’ . $no_thumb_class . $overlay_class . $field) ?>>

    To keep it simple, the post_class() function could take two optional parameters : $class and $post_id.
    (you don’t need the $post_id as you want to add a class in all blog posts).

    To add multiple $variables to the $class parameter, Divi simply use the php concatenation.
    (see php documentation about concatenation, it’s useful :

    So with the snippet above, you stock the value of your field.
    Then you use it as a $variable like the other divi $variable.

    Let me know if it helps.