您还可以在短代码中使用label参数,如下所示:
[user_meta user_id="1" label="publications"]
通过这些代码更改:
* Display the selected user meta data with a shortcode */
add_shortcode(\'user_meta\', \'user_meta_shortcode_handler\');
/* usage: [user_meta user_id="1" label="publications"] */
function user_meta_shortcode_handler($atts,$content=null){
extract( shortcode_atts( array(
\'user_id\' => \'1\',
\'label\' => \'publications\'
), $atts ) );
$output.=\'<h3>\'.$label.\'</h3>\';
$output.= wpautop(get_user_meta($user_id, \'publications\', true));
return $output;
}
EDIT:
好吧,也许你的意思是这样的:
add_action( \'show_user_profile\', \'extra_user_profile_fields\' );
/* Add Extra Fields to the User Profile */
function extra_user_profile_fields( $user ) {
?>
<table class="form-table">
<tr>
<th><label for="my_label"><?php _e("Publications Label"); ?></label></th>
<td>
<input type="text" value="<?php echo get_the_author_meta( \'my_label\', $user->ID ); ?>" name="my_label" id="my_label"/>
</td>
</tr>
<tr>
<th><label for="my_publications"><?php _e("Publications"); ?></label></th>
<td>
<textarea rows="10" cols="450" name="my_publications" id="my_publications" class="regular-text" /><?php echo get_the_author_meta( \'my_publications\', $user->ID ); ?></textarea>
</td>
</tr>
</td>
</table>
<?php
}
add_action( \'personal_options_update\', \'save_extra_user_profile_fields\' );
add_action( \'edit_user_profile_update\', \'save_extra_user_profile_fields\' );
/* Save extra user profile fields */
function save_extra_user_profile_fields( $user_id ) {
if ( !current_user_can( \'edit_user\', $user_id ) ) { return false; }
update_user_meta( $user_id, \'my_label\', esc_attr($_POST[\'my_label\']) );
update_user_meta( $user_id, \'my_publications\', esc_attr($_POST[\'my_publications\']) );
}
/* Display the selected user meta data with a shortcode */
add_shortcode(\'user_meta\', \'user_meta_shortcode_handler\');
/* usage: [user_meta user_id="1"] */
function user_meta_shortcode_handler($atts,$content=null){
extract( shortcode_atts( array(
\'user_id\' => \'1\',
), $atts ) );
$output.=\'<h3>\';
$output.= wpautop(get_user_meta($user_id, \'my_label\', true));
$output.=\'</h3>\';
$output.= wpautop(get_user_meta($user_id, \'my_publications\', true));
return $output;
}