Home › Forums › Feature Requests › Wrap field groups in unique divs with acf_form() (working feature code included) › Reply To: Wrap field groups in unique divs with acf_form() (working feature code included)
ok here are my core hack updates to allow for wrapping of field groups and optional display of field group titles in front end forms
usage:
$args = array(
wrap_field_groups' => false // don't wrap [default]
wrap_field_groups' => true // wrap without title
wrap_field_groups' => 'show_title' // wrap with title
);
acf_form($args);
api-field.php
line 474 – 480
// ACF5 core hack BEGIN
// are we opening or closing a field group?
if( $field['field_group_wrap'] === true ) {
echo $field['value'];
return;
}
// ACF5 core hack END
api-template.php
line 1273 – 1275
// ACF5 core hack BEGIN
'wrap_field_groups' => false,
// ACF5 core hack END
line 1386 – 1401
// ACF5 core hack BEGIN
// check for field group wrap
if( !empty( $args['wrap_field_groups'] ) ){
$wrapper = array(
'field_group_wrap' => true,
'value' => '<div id="'.$field_group['key'].'" class="acf_form_field_group_wrap">'
);
if ( 'show_title' === $args['wrap_field_groups']) {
$wrapper['value'] = '<div id="'.$field_group['key'].'" class="acf_postbox acf_form_field_group_wrap">
<h3 class="acf_form_field_group_title">'.$field_group['title'].'</h3>';
}
$fields[] = $wrapper;
}
// ACF5 core hack END
line 1408 – 1416
// ACF5 core hack BEGIN
// check for field group wrap
if( !empty( $args['wrap_field_groups'] ) ){
$fields[] = array(
'field_group_wrap' => true,
'value' => '</div><!-- end field group -->'
);
}
// ACF5 core hack END
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!
ACF wouldn’t be so widely used in WordPress if it didn’t have some pretty amazing capabilities. In this article, we look at a few of the features we’ll discuss during “7 things you didn’t know you could do with ACF” at #WPEDecode later this month. https://t.co/5lnsTxp81j pic.twitter.com/Yf0ThPG1QG
— Advanced Custom Fields (@wp_acf) March 16, 2023
© 2023 Advanced Custom Fields.
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 Cookie Policy. If you continue to use this site, you consent to our use of cookies.