Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

How do I turn the post title field into a textarea? WordPress

  • SOLVED

I'm creating a custom post type that only needs a title and some custom metaboxes. Specifically it's a CPT for quotes - only need the quote text, author and tags.

I'd like to be able to make the CPT title field (where it says "Enter title here") into a textarea. Appreciate your answers, thanks!

Update: I have already tried creating a CPT without the title, however this is not an ideal solution because on the Manage Quotes page, the quotes show "(no title)" - see screenshot http://cl.ly/image/1w2M3g062J1H

Answers (4)

2012-11-29

Dbranes answers:

Hi, here is one idea:

you could use a cpt excerpt field + your metaboxes and use 'excerpt_save_pre' action to write the
value of the excerpt textarea into the (hidden post_title field)






Dbranes comments:

here is an example of this idea (using the title_save_pre hook) :

add_filter('title_save_pre', 'update_post_title');

function update_post_title($title){
//print_r($_POST);
if( isset($_POST['post_excerpt']) && $_POST['post_type']=="quotes" ){
$title=$_POST['post_excerpt'];
}
return esc_html($title);
}


so when you don't use the title ffeld in your cpt setup, you can use the excerpt value to save into the title field.

(I assume the the post type is called "quotes" in the above code example)


David Wang comments:

Hi! I like your idea, but would it be possible to use replace the excerpt with the post body? This way I can make multi-paragraph quotes. Thanks!


Dbranes comments:

sure, here is the code example with post_content instead of post_excerpt


add_filter('title_save_pre', 'update_post_title');
function update_post_title($title){
//print_r($_POST);
if( isset($_POST['post_content']) && $_POST['post_type']=="quotes" ){
$title=esc_html(strip_tags($_POST['post_content']));
}
return $title;
}


David Wang comments:

Thanks, I figured out how to do what I needed from your answer :)

2012-11-29

Luis Abarca answers:

You can change it with jQuery.

But ill reccomend you to not add a title in your Custom post type and add a metabox with a textarea with label "Title", the on save_post put that information on post_title


David Wang comments:

I like your non-jQuery idea. Do you have any links or code snippets to show how that might be done? Thanks

2012-11-29

John Cotton answers:

Have you tried putting false for the title and true for editor in "supports" and then using the main editor textbox as your text area?

(See the supports option here: http://codex.wordpress.org/Function_Reference/register_post_type)

I think you're going to cause yourself all kinds of headaches trying to have multiline titles - WordPress and all plugins will assume single line....

2012-11-29

Arnav Joy answers:

when you have added code to register post type using register_post_type()
then you have or may be not passed one of the parameter as "supports" as

'supports' => array('title', 'editor', 'author', 'thumbnail', 'excerpt', 'comments' )

so delete title from here and it will hide title of the post and leave with editor only .

'supports' => array( 'editor', 'author', 'thumbnail', 'excerpt', 'comments' )