Displaying logged in user's name in header

HI I am trying to add a “howdy admin” type message in the header using this short code. but it displays the actual code below and not the output (users name)

[s2If is_user_logged_in()]
Welcome: [s2Get constant=“S2MEMBER_CURRENT_USER_DISPLAY_NAME” /].

[/s2If]

Thankyou
Paul M

Why are you putting that in the header? Those are shortcodes. They go on the page like normal content.

Hi Tim
I don’t know the method to display the users name in the header, judging by your response this is not the way to go. any idea how to do it?
Thanks

As with all shortcodes in WordPress, just use them like regular content on a post or page.

Hi Tim
I thought thats what I was doing. when I say in the header I mean where the logo and site nav might go not the head where the meta tags and css style links go.
Thanks
Paul M

I think you’re trolling now. But in case you’re not, try editing a post or page and putting it all there instead.

@paulm, how exactly you use the shortcode in the pageheader? Where you put it?

Hi Tim
Sorry if I have offended you in some way that was not my intention. I am trying to add something like “you are logged in as paulm” in the top bar, something like the admin bar in Wordpress. If I put the code in the header php it displays the actual code as text and not the output of the code
Thanks
Paul m

Hi Krumch I am using divi theme. In the divi theme there is the header.php I placed the code in the section called top bar. I have other code in there so I know it is in the right place it’s just the shot code above does not work
Thanks
Paulm

OK, first, if you not use a child theme, you must create one. Change of the main theme files will destroy your site when new version of the theme comes out and you update it.

Please show me the code in the file, plus two row above and after it. Looks like you try to run it in a wrong environment.

Thanks Krumch here is the code I had to remove a few html < to enable the html to show up in the post I also included the next lines of php either side

<?php endif; // true === $et_contact_info_defined ?>

div id=“language_wrapper”>
div id=“language_wrapper-inner”>

                   [s2If is_user_logged_in()]
                    Welcome: [s2Get constant="S2MEMBER_CURRENT_USER_DISPLAY_NAME" /].
                    [/s2If]

				/div>
			/div>

			div id="et-secondary-menu">
			

			<?php
				if ( ! $et_contact_info_defined && true === $show_header_social_icons ) {
					get_template_part( 'includes/social_icons', 'header' );
				} else if ( $et_contact_info_defined && true === $show_header_social_icons ) {
					ob_start();

OK, please try to set this:

<?php echo do_shortcode('[s2If is_user_logged_in()]
Welcome: [s2Get constant="S2MEMBER_CURRENT_USER_DISPLAY_NAME" /].
[/s2If]'); ?>

instead this:

[s2If is_user_logged_in()]
  Welcome: [s2Get constant="S2MEMBER_CURRENT_USER_DISPLAY_NAME" /].
[/s2If]

Dear Krumch
That worked perfectly.
Thankyou for helping

Glad that it worked :slight_smile:

The problem was that shortcodes are not executed at this exactly spot.