I am using this code for a front end form.
<?php acf_form(array(
‘post_title’ => true,
)); ?>
Can I control the label and the instruction for this field?
Thanks
I believe you can do it like this:
function my_acf_prepare_field( $field ) {
$field['label'] = "Changed Label";
$field['instructions'] = "Changed Instruction";
return $field;
}
add_filter('acf/prepare_field/name=_post_title', 'my_acf_prepare_field');
To learn more about this hook, please take a look at this page: https://www.advancedcustomfields.com/resources/acfprepare_field/.
Hope this helps 🙂
Hi James — I just implemented this and it works. However, it changes the name of my Title field on all my front-end forms. I’m trying to figure out how I might apply this to just one form. Any suggestions?
Okay, a full night’s sleep allowed me to figure out the obvious solution:) I just used a little logic to check the page template. Although I did have to make sure to exit out if there was no change so the “Title” label showed up on other forms as usual.
function my_acf_prepare_field( $field ) {
if ( is_page_template('my-page-template.php') ) {
$field['label'] = "Changed Label";
$field['instructions'] = "Changed Instruction";
}
if ( $field ) {
return $field;
} else {
exit;
}
}
add_filter('acf/prepare_field/name=_post_title', 'my_acf_prepare_field');
Has anyone a idea how to check the post type when using prepare field?
My form is generated in a shortcode, so using the global $post is not a option.
The topic ‘Front End Form Title Label’ is closed to new replies.
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.