Title: echo username into code
Last modified: August 20, 2016

---

# echo username into code

 *  [ryanpym](https://wordpress.org/support/users/ryanpym/)
 * (@ryanpym)
 * [13 years, 8 months ago](https://wordpress.org/support/topic/echo-username-into-code/)
 * Hi,
    I am currently fiddling round with the latest posts by author plugin.
 * At present, you can put the plugin into the theme pages by using `<?php echo 
   do_shortcode('[latestbyauthor author="username" show="3"]'); ?>` This requires
   you to manually input the authors username.
 * I am trying to automate this setting the user name based on the users profile
   you are viewing – here is the user profile page for reference: [http://www.copymusic.co.uk/COPYmusicscout2/](http://www.copymusic.co.uk/COPYmusicscout2/)
 * Now I am familiar with how to pull the relevent users name, as I have used the
   following code to correctly display the “view uploads by xxxxx” link. I have 
   been using the following: `<?php echo $user->screenname; ?>`.
 * I therefore tried using `<?php echo do_shortcode('[latestbyauthor author="<?php
   echo $user->screenname; ?>" show="3"]'); ?>` which didn’t work.
 * I read something online which suggested the 2nd echo wasn’t required so I tried`
   <?php echo do_shortcode('[latestbyauthor author=" $user->screenname" show="3"]');?
   >` which again didn’t work.
 * I am therefore a little stuck . . At the moment it is just displaying the last
   few posts onto the site, I have fiddle around manually inputting the relevent
   user name and it does work, but obviously shows the same posts regardless of 
   user profile!
 * I am pretty familiar with some PHP so can take simple instructions, unfortunately
   I am a bit stuck at this time!
 * Any suggestions will be greatly appreciated, if you need any more detail, please
   let me know!
 * Many thanks
    Ryan

Viewing 2 replies - 1 through 2 (of 2 total)

 *  Moderator [bcworkz](https://wordpress.org/support/users/bcworkz/)
 * (@bcworkz)
 * [13 years, 8 months ago](https://wordpress.org/support/topic/echo-username-into-code/#post-3250884)
 * Right now, you are saying the author’s name is literally the string “$user->screenname”,
   the element is not getting resolved to the proper value. You need to readjust
   the syntax. Note the quote switch, this allows variables to be resolved.
    `<?
   php echo do_shortcode("[latestbyauthor author='$user->screenname' show='3']");?
   >` This will fix the syntax, not totally sure $user->screenname will actually
   work still. You may need to add `$name = get_the_author_meta('display_name');`
   before the echo and use the $name variable in place of $user->screenname.
 *  Thread Starter [ryanpym](https://wordpress.org/support/users/ryanpym/)
 * (@ryanpym)
 * [13 years, 8 months ago](https://wordpress.org/support/topic/echo-username-into-code/#post-3250885)
 * Many tanks bcworkz, re-adjusting the syntax did the trick! no need to add the
   rest!
 * Once again another fine response from the WordPress community.
 * Kind Regards,
    Ryan

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘echo username into code’ is closed to new replies.

## Tags

 * [php](https://wordpress.org/support/topic-tag/php/)

 * In: [Hacks](https://wordpress.org/support/forum/plugins-and-hacks/hacks/)
 * 2 replies
 * 2 participants
 * Last reply from: [ryanpym](https://wordpress.org/support/users/ryanpym/)
 * Last activity: [13 years, 8 months ago](https://wordpress.org/support/topic/echo-username-into-code/#post-3250885)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
