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

Make custom textarea field respect paragraph breaks WordPress

  • SOLVED

As per the code example below (functions.php), I have created a custom textarea field in the backend profile area... The fields are working correctly, however I have the following problem with the textarea field Bio Description (brand_desc)...

When I enter paragraph text into this backend profile field it saves correctly, however when I attempt to display this information on the frontend it displays it as one entire text string without respecting the paragraph breaks that were inserted when entered in the custom profile field backend...

I would like to have the saved meta data field respect the carriage returns or paragraph breaks...

Any help would be greatly appreciated...

Thanks,
Sean.

add_action( 'show_user_profile', 'my_show_extra_profile_fields' );
add_action( 'edit_user_profile', 'my_show_extra_profile_fields' );

function my_show_extra_profile_fields($user) {?>

<?php if($user->has_cap('s2member_level2')) { // Custom fields only display to business accounts?>

<h3>Your Company Details</h3>

<table class="form-table">

<tr>

<th><label for="age">Business Name</label>
</th>
<td><input type="text" name="business_name" id="business_name" required value="<?php echo esc_attr(get_the_author_meta( 'business_name', $user->ID ) ); ?>" class="regular-text" /> <br />
<span class="description">Please enter your age. <strong>(Required)</strong></span>
</td>
</tr>


</table>

<?php } if($user->has_cap('s2member_level1')) {// Custom fields only display to Level 1 accounts?>

<h3>Your Personal Brand</h3>

<table class="form-table">

<tr>

<th><label for="brand_desc">Bio Description</label>
</th>
<td>

<textarea name="brand_desc" id="brand_desc" style="width:100%;" class="regular-text" rows="8" cols="30"/><?php echo esc_attr(get_the_author_meta( 'brand_desc', $user->ID ) ); ?></textarea><br />
<span class="description">Please enter your bio description. <strong>(Required)</strong></span>
</td>
</tr>

</table>

<?php } }

add_action( 'personal_options_update', 'my_save_extra_profile_fields' );
add_action( 'edit_user_profile_update', 'my_save_extra_profile_fields' );

function my_save_extra_profile_fields( $user_id ) {

if ( !current_user_can( 'edit_user', $user_id ) )

return false;

if(!empty( $_POST['business_name'])){

update_usermeta( $user_id, 'business_name', $_POST['business_name'] );

}

if(!empty( $_POST['brand_desc'])){

update_usermeta( $user_id, 'brand_desc', $_POST['brand_desc'] );

}
}

Answers (1)

2014-01-03

Ryan S answers:

In the front-end area where you echo User description just add wpautop();, e.g.


$brand_desc = USER_META;
echo wpautop( $brand_desc );



Hope that helps


Sean Gartlan comments:

Thanks for the response...

I added <?php echo wpautop ($curauth->brand_desc);?> and it works perfectly...

Many thanks for the quick correct answer...

Sean.


Sean Gartlan comments:

Using this method places a <p></p> before the string variable & respects paragraph breaks of the string by adding <p></p> and also adds a <p></p> to the end...

Is it possible for this function to not add the very first <p></p> before the string variable as this is unwanted for my scenario???

Thanks,
Sean.