WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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/)


share|improve this question
Why don't you simply add the attributes in the code? – kaiser Jun 7 '11 at 18:57
up vote 3 down vote accepted

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 somehting 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>'
share|improve this answer

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.

share|improve this answer

The correct code for a textarea is:

<textarea cols=20 rows=20 name=mytext>Content</textarea>
share|improve this answer
@kaiser, tosho is right, I didn't even see that your html was wrong for textarea.. I updated my answer. – mike23 Jun 7 '11 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 '11 at 20:07
@user5486 rows="5" /> is broken. Remove the forward slash. – toscho Jun 7 '11 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>
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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