Home › Forums › Feature Requests › Post Title/Content Labels
Back in July, there was a request for a feature that would allow you to customize the labels used for the post_title and post_content fields. The feature was supposed to have been implemented but it was not.
Feature Request: Edit label for post_title and post_content in acf_form
This is really easy to accomplish.
In \api\api-template.php:
function acf_form( $args = array() ) {
// vars
$url = home_url( $_SERVER['REQUEST_URI'] );
// defaults
$args = wp_parse_args( $args, array(
'id' => 'acf-form',
'post_id' => false,
'new_post' => false,
'field_groups' => false,
'fields' => false,
'post_title' => false,
'post_content' => false,
/* [patch] */
'post_title_label' => 'Title',
'post_content_label' => 'Content',
/* [/patch] */
'form' => true,
Below that:
// post_title
if( $args['post_title'] )
{
$fields[] = acf_get_valid_field(array(
'name' => '_post_title',
/* [patch] */
'label' => $args['post_title_label'],
/* [/patch] */
'type' => 'text',
'value' => $post_id ? get_post_field('post_title', $post_id) : '',
'required' => true
));
}
// post_content
if( $args['post_content'] )
{
$fields[] = acf_get_valid_field(array(
'name' => '_post_content',
/* [patch] */
'label' => $args['post_content_label'],
/* [/patch] */
'type' => 'wysiwyg',
'value' => $post_id ? get_post_field('post_content', $post_id) : ''
));
}
Now you can use post_title_label and post_content_label with acf_form().
<?php acf_form(array(
'field_groups' => array(341),
'post_id' => 'new_post',
'post_title' => true,
'post_content' => true,
'post_title_label' => 'New Title',
'post_content_label' => 'New Description',
'submit_value' => 'Submit Post'
)); ?>
You can do it like this without overwriting the core code:
add_filter( 'acf/get_valid_field', 'change_input_labels');
function change_input_labels($field) {
if($field['name'] == '_post_title') {
$field['label'] = 'Custom Title';
}
if($field['name'] == '_post_content') {
$field['label'] = 'Custom Content Title';
}
return $field;
}
This code goes into your functions.php file for example.
Since i think not too many people needs this function, i don’t think we need a GUI for this, so we can mark this feature request as solved.
@passatgt This is a great solution for the labels, but here is a different twist to this. Is it possible to change the WYSIWYG Editor to basic and media upload to false?
if( $field['type'] == 'wysiwyg' ) {
$this->defaults = array(
'toolbar' => 'basic',
'media_upload' => 0
)
}
I know this is not working code but it’s the idea I’m looking for. Any ideas?
I just found a solution to my problem. Here is the working code:
// Change Post Content Type
add_filter( 'acf/get_valid_field', 'change_post_content_type');
function change_post_content_type( $field ) {
if($field['type'] == 'wysiwyg') {
$field['tabs'] = 'visual';
$field['toolbar'] = 'basic';
$field['media_upload'] = 0;
}
return $field;
}
I’m not exactly sure how this is done, but you might be able to if you check for a specific field ID or Key within the form you targeting.
if($field['id'] == 'field_xxxxxxxxxxx') {
// execute your code
}
For current ACF version (5.4.2) the title customization may look like this:
function my_acf_load_field( $field ) {
$field['label'] = 'Your custom name';
return $field;
}
add_filter('acf/load_field/name=_post_title', 'my_acf_load_field');
The topic ‘Post Title/Content Labels’ 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.