Site logo

[Resolved] Display designation in user archives

Home Forums Support [Resolved] Display designation in user archives

Home Forums Support Display designation in user archives

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #2397382
    George

    I am displaying the author name in my author archive template with a dynamic headline but I also want to display a designation. Basically, I would like to display “Founder” if the user ID equals to 1, otherwise I would like to display “Contributor”.

    I’ve created a shortcode for this but it doesn’t seem to work:

    function display_author_archive_designation() { 
    	$user_info = get_userdata( $user_id );
    
    	ob_start();
    
    	if ( $user_info->ID === 1 ) {
    		echo "Founder";
    	} else {
    		echo "Contributor";
    	}
    
    	return ob_get_clean();
    }
    
    add_shortcode( 'author_archive_designation', 'display_author_archive_designation' );

    It always displays “Contributor”. Is there something wrong with the code?

    #2397518
    Fernando
    Customer Support

    Hi George,

    Can you try this instead?:

    function display_author_archive_designation() { 
    	$user_info = get_user_by( 'slug', get_query_var( 'author_name' ) );
    	ob_start();
    	if ( $user_info->ID === 1 ) {
    		echo "<h2>Founder</h2>";
    	} else {
    		echo "<h2>Contributor</h2>";
    	}
    
    	return ob_get_clean();
    }
    
    add_shortcode( 'author_archive_designation', 'display_author_archive_designation' );
    #2398305
    George

    Thanks Fernando, it worked. Also, this worked for me:

    function display_author_archive_designation() { 
    	ob_start();
    
    	if ( get_the_author_meta('ID') === 1 ) {
    		echo "Founder";
    	} else {
    		echo "Contributor";
    	}
    
    	return ob_get_clean();
    }
    
    add_shortcode( 'author_archive_designation', 'display_author_archive_designation' );
    #2399131
    Fernando
    Customer Support

    You’re welcome George! Thank you for sharing!

Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.