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 : https://www.php.net/manual/en/language.operators.string.php).
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.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.