WordPress.org

Ready to get started?Download WordPress

Forums

Display WP function with CSS style (2 posts)

  1. hoofedcracker
    Member
    Posted 1 year ago #

    Hi Guys,
    Got some PHP here that I need some input for;
    Here is just a rough idea of what I am getting at:

    <style>.first:first-letter{text-transform: uppercase;}</style>

    <?php
     if (is_user_logged_in() ) {
       $user = wp_get_current_user();
       echo 'Hi <span class="first">' . $user->display_name . '</span>!';
     } else{
       echo 'Hi Guest!';
     }
    ?>

    I am not getting any results with the styling. i.e First letter of $user->display_name will not be transformed with a Capital Letter at the start.

    I will be needing to edit some WP function i.e. display_name() or wp_get_current_user(), Would that be correct? If so, could you provide me with the file_name.php to edit?

    BTW, We are allowed to post up to 10 lines of code in the forums, correct? : )

    Thank you in advance!

    Cheers!

  2. petyata
    Member
    Posted 1 year ago #

    You missed a part in the code, however helped me to solve this issue by myself :). Here is my code, adjust it appropriately:

    <?php
       if (is_user_logged_in() ) {
    	wp_get_current_user();
    	$current_user = wp_get_current_user();
    	 	if ( !($current_user instanceof WP_User) )
    	    	return;
    	   	echo 'You are currently logged in as <span id="user-loged-name">' . $current_user->user_login . '</span><br />';
    		 wp_loginout( home_url()); // Display "Log Out" link.
    	}
    ?>

Topic Closed

This topic has been closed to new replies.

About this Topic