0

I need to add a custom field to my article post but not sure how to add an additional class to it.

Currently the classes get pulled through like this <?php post_class($classes); ?>.

However I need to add a custom field to this as well. To demonstrate ive added a class= but this doesnt work as class= is being added twice.

<?php post_class($classes); ?> class="<?php the_field( "size" ); ?>

So i need post_class and the_field to work together.

1

I would first store your field value in a variable after your loop just before the posts HTML tags start:

<?php
$size = the_field( "size" );
?>

And then add this variable to the post class function:

<?php post_class($size); ?>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.