Here's the code for a custom metabox. Very simply, how would I resize the textarea box? I'd like to add an expression such as cols="50" rows="5".

// Echo out the field
    echo '<p>Enter the location:</p>';
echo '<div class="customEditor"><input type="textarea" name="_location" value="' . $location  . '" class="widefat" /></div>';
    echo '<p>How Should People Dress?</p>';
    echo '<input type="textarea" name="_dresscode" value="' . $dresscode  . '" class="widefat" />';

(Source: http://wptheming.com/2010/08/custom-metabox-for-post-type/)


  • Why don't you simply add the attributes in the code?
    – kaiser
    Jun 7, 2011 at 18:57

4 Answers 4


You could try styling it with CSS by adding an ID or a class to the textarea and inserting styles into the wp_admin head.

Or, a quick way would be to do something like this :

echo '<textarea name="_dresscode" class="widefat" style="width:400px !important; height:80px !important;" >' . $dresscode  . '</textarea>';

If not, have you tried simply :

echo '<textarea name="_dresscode" class="widefat" cols="50" rows="5">' . $dresscode  . '</textarea>'

While using the cols attribute of the textarea tag is one way to set the width of a text area in a metabox form, this method won't respond very well to the user resizing the WordPress window. To respond to the resizing of the window, you may want to include an inline style attribute as well. For example:

<textarea name="myName" id="myId" rows="5" cols="60" style="width:99%">Stuff to fill the box</textarea>

The width:99% will override the cols on browsers that understand CSS (pretty much all of them) and keep your text area proprerly sized.


The correct code for a textarea is:

<textarea cols=20 rows=20 name=mytext>Content</textarea>
  • @kaiser, tosho is right, I didn't even see that your html was wrong for textarea.. I updated my answer.
    – mike23
    Jun 7, 2011 at 19:38
  • Mike and @toscho, this one worked. Many thanks. echo '<textarea name="_dresscode" class="widefat" cols="50" rows="5" />' . $dresscode . '</textarea>'
    – user5486
    Jun 7, 2011 at 20:07
  • @user5486 rows="5" /> is broken. Remove the forward slash.
    – fuxia
    Jun 7, 2011 at 23:57

Meta Box For Text Area

This includes a custom field named wpsites_textarea.

<p><label for="wpsites_textarea" class="screen-reader-text"><b><?php _e( 'Genesis Style Meta Box', 'genesis' ); ?></b></label></p>
<p><textarea class="widefat" rows="4" cols="4" name="wpsites_textarea" class="inside"><?php echo esc_textarea( genesis_get_custom_field('wpsites_textarea') ); ?></textarea></p>
<p><?php printf( __( 'Suitable for text and HTML. May include %s tags. <a href=" http://example.com/" target="_blank">Learn more about custom meta boxes.</a>', 'genesis' ), genesis_code( 'HTML' ) ); ?></p>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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