Support » Plugins » How to add a registered user "signature" to each comment

  • I’d like each logged in user of my site (i.e. those with an account) to be able to create a “signature” tag, similar to that used on forums, to be displayed on any comments they leave.

    Is there a plugin or other way to do this?

Viewing 1 replies (of 1 total)
  • Not a plugin, but this tutorial seems easy enough to implement
    to get the same result. For anyone interested.

    You just need to add some code to the functions.php file that creates custom fields in the user profile and then retrieve those meta details into your theme.

    Adding and using custom user profile fields

    Open your theme’s functions.php file and drop this PHP code in:

    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 ) { ?>
    	<h3>Extra profile information</h3>
    	<table class="form-table">
    			<th><label for="twitter">Twitter</label></th>
    				<input type="text" name="twitter" id="twitter" value="<?php echo esc_attr( get_the_author_meta( 'twitter', $user->ID ) ); ?>" class="regular-text" /><br />
    				<span class="description">Please enter your Twitter username.</span>
    <?php }

    Also in the functions.php file to save the custom fields:

    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;
    	/* Copy and paste this line for additional fields. Make sure to change 'twitter' to the field ID. */
    	update_usermeta( $user_id, 'twitter', $_POST['twitter'] );

    and finally this to your functions.php file to display the meta-data

    function my_author_box() { ?>
    	<div class="author-profile vcard">
    		<?php echo get_avatar( get_the_author_meta( 'user_email' ), '96' ); ?>
    		<h4 class="author-name fn n">Article written by <?php the_author_posts_link(); ?></h4>
    		<p class="author-description author-bio">
    			<?php the_author_meta( 'description' ); ?>
    		<?php if ( get_the_author_meta( 'twitter' ) ) { ?>
    			<p class="twitter clear">
    				<a href="<?php the_author_meta( 'twitter' ); ?>" title="Follow <?php the_author_meta( 'display_name' ); ?> on Twitter">Follow <?php the_author_meta( 'display_name' ); ?> on Twitter</a>
    		<?php } // End check for twitter ?>

    Now in the single.php file you can add this after the post has been displayed:

    <?php my_author_box(); ?>

Viewing 1 replies (of 1 total)
  • The topic ‘How to add a registered user "signature" to each comment’ is closed to new replies.