Site logo

Archived topic

Users first name in page editor h2

5 replies · Started by chris on April 26, 2021

Viewing posts 1–6 of 6

Hey! So,

I have the users name in the navigation, however i was wondering if its possible to display the users name on the page editor, when adding h2 text?

For example on my contact page, rather than the title being “How can we help?”

Id like it to be “Hello [firstname], How can we help?”

Ps also on some pages the small browser icon at the top of the page, displays a stock world image (not showing the one i choose)

Cleared cache etc, works on some pages and not others?

Thank you very much for the continued support.

Hi there,

try adding this PHP Snippet:

function db_display_user_firstname( $user_id = null ) {

	$user_info = $user_id ? new WP_User( $user_id ) : wp_get_current_user();

	if ( $user_info->first_name ) {

		return $user_info->first_name;
	}

	return 'fall back text'; // set text to be displayed if user has not registered firstname
}
add_shortcode('firstname', 'db_display_user_firstname');

Then you can use the [firstname] shortcode

Lovely, Added the snippet provided then used the html block to get text positioned with CSS. Fantastic thanks David!

Great to hear that - if you use GenerateBlocks Headline Block - it supports Shortcodes :)

Awesome! Did try that but didn't work, perhaps I tried before the snippet was life haha! If that works awesome be even easier solution to anyone looking!!^^^

Thanks very much David.

Glad to be of help

This archived topic is closed to new replies.