John Davidson

php - Format/Style current_user_display_name in WP

0 comments
Message:


I am fairly new to coding and need a little guidance. I am using the following .php:


// [current_user_display_name]

function display_current_user_display_name () {
$user = wp_get_current_user();
$display_name = $user->display_name;
return $user->display_name;
}
add_shortcode('current_user_display_name', 'display_current_user_display_name');

and would like to style the text with CSS. I'm not sure how to do this, I tried this:


.display_current_user_display_name 

{
color:#ffffff;
font-family:lato;
font-size:16px;
font-weight:regular;
}

but it did not work. Thanks!



My Answer:
>display_name;_ echo "

$display_name

";_}_display_current_user_display_name();?>

In this code snippet, the current user's display name is retrieved using the wp_get_current_user() function and stored in the $display_name variable. The display name is then echoed out in a paragraph element with a bold font weight and blue color.

You can customize the style of the display name by modifying the inline CSS within the echo statement. For example, you can change the font size, font family, text alignment, etc. to suit your design preferences.

Remember to always sanitize and validate user input to prevent security vulnerabilities in your code.

Rate this post

5 of 5 based on 9394 votes

Comments




© 2024 Hayatsk.info - Personal Blogs Platform. All Rights Reserved.
Create blog  |  Privacy Policy  |  Terms & Conditions  |  Contact Us