Site logo

Archived topic

Display designation in user archives

3 replies · Started by George on November 1, 2022

Viewing posts 1–4 of 4

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?

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' );

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' );

You're welcome George! Thank you for sharing!

This archived topic is closed to new replies.