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. PHP code inside shortcodes
  20. Using Multiple Submit buttons to trigger customised php functions
  21. Shortcode content filter?
  22. Trigger popup in a php if/else statement
  23. How to output a PHP file values by shortcode?
  24. Showing content from one page on another
  25. How to display posts by current user in a drop down
  26. How to store data from multiple forms using ajax and php
  27. Get value from shortcode to do something
  28. Custom shortcode outputs plain text instead of HTML at top of post
  29. Pass php dynamic variable to shortcode
  30. How to Reference/Echo Variable from Another PHP Function
  31. Remove echo from shortcode
  32. Shortcode with PHP issue “Undefined index”
  33. Shortcode from a function not working
  34. Display Data in Table from External Database in WP using Shortcodes
  35. Is it possible to return content, and then also continue to do other things?
  36. ::before on open/close function [closed]
  37. Is it possible to define variables in a wordpress shortcode, and then call the shortcode using a specific variable?
  38. Creating WordPress Shortcode with Variable
  39. Shortcode to find and replace URL
  40. How to put a form with php code into a variable or shortcode?
  41. Help with WordPress function inside a shortcode
  42. calling a custom field value inside functions.php
  43. WordPress shortcode returns the data before
  44. AJAX function not working [closed]
  45. Updating Metadata with Shortcode
  46. Display logged in user name and lastname on page
  47. Create shortcode for metabox gallery
  48. Trying to update Woocommerce meta values
  49. Display Visual Composer shortcode if a post belongs in specific categories
  50. Why is the current page loaded in the pop-up window and not the specified one?
  51. Billing detail page doesn’t work after I’ve changed the order of the Woocommerce navigation
  52. How do I reopen the (Popup Maker) after entering the correct password for a password protected page?
  53. Block error message in foreach loop when looping through ACF field
  54. How can I prevent a shortcode div from extending beyond its boundaries?
  55. Gravity Forms: How to add PHP function to confirmation conditional shortcode?
  56. How to change this ajax function to submit to the default wordpress content area instead of the custom field ‘seller notes’?
  57. wpdb->query returns different value to phpMyAdmin
  58. shortcodes, custom php and their errors
  59. Display a custom name when the user has no name settle in his account
  60. Having trouble creating two shortcodes, one for logged in user and one for visitors
  61. Display current user metadata on WordPress page
  62. Reload page with a different shortcode when a user selects from a dropdown
  63. How Can I Display the Last Modified Date for User Profiles on WordPress?
  64. PHP/CSS: Shortcode won’t display correctly, and only displays in the head (before content)
  65. Offset with ajax load more posts duplicates
  66. Get posts by id using shortcode
  67. Shortcode’s output to use as other shortcode’s parameter
  68. Creating wordpress user registration form
  69. Open/closed function [closed]
  70. Need to Echo A Url path to show on a wordpress page
  71. Wrapping shortcode content in a span or link
  72. Need help with PHP functions
  73. How to set up an auto delete post?
  74. Styling admin page rows in order of importance (checkboxes)
  75. How to have Function of a plugin using global vars into a shortcode?
  76. Overwriting a Shortcode
  77. Shortcoding with Divs
  78. Display default WordPress login/registration form into a modal window
  79. Trouble using wordpress functions in a pop-up modal form
  80. ajax form function error
  81. Send foreach $_post method to contact form 7 [closed]
  82. Whats wrong with my code? Need To add String to shortcode? [closed]
  83. My title is showing after the shortcode
  84. A next page function with shortcode?
  85. Shortcode to include PHP file, pass various parameters to include?
  86. Contact form with dynamic dropdown and filter
  87. WP Custom tables query
  88. Display terms on product page with shotrcode
  89. Redirect loop upon installation of my plugin
  90. How call WordPress shortcode inside function file
  91. Show Login Errors In WordPress/Elementor (Code “works”, but breaks site)
  92. Calling a function via a shortcode in javascript
  93. Adding a css class to the gallery
  94. Strip and print only the numbers found in current’s post excerpt (even if they are without space)
  95. Woocomerce custom add to cart button edit functionality [closed]
  96. Display endpoint’s return into a file (file_put_contents())
  97. Automatically populating a date parameter within a shortcode
  98. Custom PHP contact form issue
  99. Trouble getting wpdb to work – first time
  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
  • Post Navigation Elementor
  • Custom Elementor controls not appearing in the widget Advanced tab using injection hooks
  • WPFacet multiple loop displaying duplicate content
  • Get the name of the template/*html file used
  • Fix: WordPress.DB.PreparedSQL.NotPrepared Plugin Check (PCP)
  • Removing unnecessary CSS and JS code from wp_head()
  • hexagonal image gallery. Am I on the right track? [closed]
  • Trying to Add Paging to Single Post Page
  • Sharing media files between live and staging servers
© 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