Skip to content
Read For Learn
Read For Learn
  • Database
    • Oracle
    • SQL
  • C
  • C++
  • Java
  • Java Script
  • jQuery
  • PHP
Read For Learn
  • Database
    • Oracle
    • SQL
  • C
  • C++
  • Java
  • Java Script
  • jQuery
  • PHP

Shortcode to embed Edit Account form not working

You absolutely did not understand how the code from my previous answer works, yeah? The PHP ternary operator $result = $a ? $b : $c works the same way as the following construction:

if ( $a ) {
    $result = $b;
} else {
    $result = $c;
}

So the whole idea was to check if the get_user_meta(get_current_user_id(), 'last_name', true) function returns an empty value. When you change it to

($username = get_user_meta(get_current_user_id(), 'last_name', true)  . '</a>') ? ...

you break the whole logic, because that

get_user_meta(get_current_user_id(), 'last_name', true)  . '</a>'

string would never have an empty value (that should be quite obvious, even if the get_user_meta() function returns an empty value, the whole string would be equal to '</a>'). Use this statement:

return '&nbsp;<a href="' . admin_url('profile.php') . '">' . ( ( $username = get_user_meta( get_current_user_id(), 'last_name', true ) ) ? $username : ">Noe Name [edit profile]" ) . '</a>';

Update

If you want to work with several user meta fields, I recommend to use get_userdata() function:

function colaborador_nome($atts)
{
    if (is_user_logged_in() && !is_feed()) {
        $userdata = get_userdata( get_current_user_id() );
        $username = trim( implode( ' ', array( $userdata->first_name, $userdata->last_name ) ) );
        return '&nbsp;<a href="' . admin_url('profile.php') . '">' . ( $username ? $username : ">Noe Name [edit profile]" ) . '</a>';
    }
}

I still don’t understand why the shorthand form of ternary operator doesn’t work for you, using it would help to simplify the return statement to

return '&nbsp;<a href="' . admin_url('profile.php') . '">' . ( $username ?: ">Noe Name [edit profile]" ) . '</a>';

Related Posts:

  1. PHP multiple forms, same page, isset($_POST[]) not working?
  2. How to manually fix the WordPress gallery code using PHP in functions.php?
  3. Shortcode putting html such as
  4. Inserting Gravity Form checkbox values into Advanced Custom Fields [closed]
  5. Counting number of posts in a category and its sub categories and displaying result using shortcode
  6. Shortcode created to check language not works
  7. Creating wordpress user registration form
  8. Add/echo div with Analytics-Code to function in functions.php
  9. Custom plugin issue when trying to use the shortcode twice on a page [closed]
  10. How can I default to all WordPress roles when parameter is not included in shortcode?
  11. WordPress menu deletes when trying to add a hook
  12. Wrap each shortcode in array to div
  13. Recent post display using shortcode
  14. Nested shortCode functions in the functions.php file
  15. Making Quote Plugin more efficient
  16. Placing raw HTML inside a WordPress shortcode
  17. Shortcode content output but not in correct place
  18. is_page “range” for if statement?
  19. Using Multiple Submit buttons to trigger customised php functions
  20. Shortcode content filter?
  21. Trigger popup in a php if/else statement
  22. How to output a PHP file values by shortcode?
  23. Showing content from one page on another
  24. How to display posts by current user in a drop down
  25. How to store data from multiple forms using ajax and php
  26. Get value from shortcode to do something
  27. Custom shortcode outputs plain text instead of HTML at top of post
  28. Pass php dynamic variable to shortcode
  29. How to Reference/Echo Variable from Another PHP Function
  30. Shortcode with PHP issue “Undefined index”
  31. Shortcode from a function not working
  32. Display Data in Table from External Database in WP using Shortcodes
  33. Is it possible to return content, and then also continue to do other things?
  34. ::before on open/close function [closed]
  35. Is it possible to define variables in a wordpress shortcode, and then call the shortcode using a specific variable?
  36. Creating WordPress Shortcode with Variable
  37. Shortcode to find and replace URL
  38. How to put a form with php code into a variable or shortcode?
  39. Help with WordPress function inside a shortcode
  40. calling a custom field value inside functions.php
  41. List all blogs, but exclude the main site
  42. Shortcode for Listing Users from Meta Value?
  43. Cant display an image via PHP in wordpress
  44. Need to Modify a WordPress Shortcode with another wordpress shortcode
  45. How to return a string that has a jQuery and Ajax inside in a shortcode?
  46. Create special button on WP Tiny MCE Posts Editor for Shortcodes
  47. AJAX function not working [closed]
  48. Updating Metadata with Shortcode
  49. Display logged in user name and lastname on page
  50. Create shortcode for metabox gallery
  51. Trying to update Woocommerce meta values
  52. Display Visual Composer shortcode if a post belongs in specific categories
  53. Why is the current page loaded in the pop-up window and not the specified one?
  54. Billing detail page doesn’t work after I’ve changed the order of the Woocommerce navigation
  55. How do I reopen the (Popup Maker) after entering the correct password for a password protected page?
  56. How can I prevent a shortcode div from extending beyond its boundaries?
  57. Gravity Forms: How to add PHP function to confirmation conditional shortcode?
  58. How to change this ajax function to submit to the default wordpress content area instead of the custom field ‘seller notes’?
  59. wpdb->query returns different value to phpMyAdmin
  60. shortcodes, custom php and their errors
  61. Display a custom name when the user has no name settle in his account
  62. Having trouble creating two shortcodes, one for logged in user and one for visitors
  63. Display current user metadata on WordPress page
  64. Reload page with a different shortcode when a user selects from a dropdown
  65. How Can I Display the Last Modified Date for User Profiles on WordPress?
  66. PHP/CSS: Shortcode won’t display correctly, and only displays in the head (before content)
  67. Offset with ajax load more posts duplicates
  68. Get posts by id using shortcode
  69. Shortcode’s output to use as other shortcode’s parameter
  70. Creating wordpress user registration form
  71. Open/closed function [closed]
  72. Need to Echo A Url path to show on a wordpress page
  73. Wrapping shortcode content in a span or link
  74. Need help with PHP functions
  75. How to set up an auto delete post?
  76. Styling admin page rows in order of importance (checkboxes)
  77. How to have Function of a plugin using global vars into a shortcode?
  78. Overwriting a Shortcode
  79. Shortcoding with Divs
  80. Display default WordPress login/registration form into a modal window
  81. Trouble using wordpress functions in a pop-up modal form
  82. ajax form function error
  83. Send foreach $_post method to contact form 7 [closed]
  84. Whats wrong with my code? Need To add String to shortcode? [closed]
  85. My title is showing after the shortcode
  86. A next page function with shortcode?
  87. Shortcode to include PHP file, pass various parameters to include?
  88. Contact form with dynamic dropdown and filter
  89. WP Custom tables query
  90. Display terms on product page with shotrcode
  91. Redirect loop upon installation of my plugin
  92. How call WordPress shortcode inside function file
  93. Show Login Errors In WordPress/Elementor (Code “works”, but breaks site)
  94. Calling a function via a shortcode in javascript
  95. Adding a css class to the gallery
  96. Strip and print only the numbers found in current’s post excerpt (even if they are without space)
  97. Woocomerce custom add to cart button edit functionality [closed]
  98. Display endpoint’s return into a file (file_put_contents())
  99. Automatically populating a date parameter within a shortcode
  100. How can I process a form submission from an HTTP POST request?
Categories PHP Tags account, forms, functions, php, shortcode
Divi: how to hide/show specific menu according current page?
On the Blogpost I have categories showing, is there a way to exclude a catgegory like ‘Media’?

Recommended Hostings

Cloudways: Realize Your Website's Potential With Flexible & Affordable Hosting. 24/7/365 Support, Managed Security, Automated Backups, and 24/7 Real-time Monitoring.

FastComet: Fast SSD Hosting, Free Migration, Hack-Free Security, 24/7 Super Fast Support, 45 Day Money Back Guarantee.

Recent Added Topics

  • Bug in translation system: load_theme_textdomain() returns true, files are available and accessible but the language defaults to english
  • Custom Elementor controls not appearing in the widget Advanced tab using injection hooks
  • Get the name of the template/*html file used
  • Trying to Add Paging to Single Post Page
  • Sharing media files between live and staging servers
  • How to display the description of a custom post type in the dashboard?
  • Critical error on image display
  • Copying WP data and files into new install?
  • How to determine the DirectAdmin WordPress backup date?
  • How to get list of ALL tables in the database?
© 2026 Read For Learn
  • Database
    • Oracle
    • SQL
  • algorithm
  • asp.net
  • assembly
  • binary
  • c#
  • Git
  • hex
  • HTML
  • iOS
  • language angnostic
  • math
  • matlab
  • Tips & Trick
  • Tools
  • windows
  • C
  • C++
  • Java
  • javascript
  • Python
  • R
  • Java Script
  • jQuery
  • PHP
  • WordPress