Support

Account

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

  • Hi there,

    Looks like you’ll need to use a child theme here.

    If you modify directly your theme, your modifications will be suppressed when you’ll update your theme.

    You’re lucky! The Divi Elegant Theme documentation is well done for that :
    https://www.elegantthemes.com/blog/divi-resources/divi-child-theme

    Just follow the instructions to overwrite properly your blog.php template.

    Then you could add your custom field value to post_class() with acf function “the_field()”.
    Your modified blog.php template will probably look like this :

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

    You can also check the WordPress documentation about the post_class() function: https://developer.wordpress.org/reference/functions/post_class/

    Hope it helps.