Title: php inserting code into shortcode help
Last modified: August 20, 2016

---

# php inserting code into shortcode help

 *  [posthawk](https://wordpress.org/support/users/posthawk/)
 * (@posthawk)
 * [13 years, 2 months ago](https://wordpress.org/support/topic/php-inserting-code-into-shortcode-help/)
 * What i’m trying to make is a widget that will display a twitter widget through
   shortcode, but it will automatically insert the author of the post’s twitter 
   id as the username. The id is gotten through the users profile.
 *     ```
       <?php
       //this retrieves the authors twitter username
       $tweetid = get_the_author_meta( 'twitter' );
       //this should enter that username unto the required field of the shortcode
       $tweetcode = '[rotatingtweets screen_name="$tweetid"]';
       //this tells the widget not to display if there is no twitter data filled out
       $tweetcheck = get_the_author_meta( 'twitter' );
   
       if ($tweetcheck)  { ?
   
       //this should run the shortcode with the propper field filled out
   
       <?php
        echo do_shortcode($tweetcode);
       ?>
   
       <?php } ?>
       ```
   
 * _[Please use the code buttons OR backticks (not blockquote) for posting code –
   as is, it’s likely your code has been corrupted here. [http://codex.wordpress.org/Forum\_Welcome#Posting\_Code](http://codex.wordpress.org/Forum_Welcome#Posting_Code)]_
   
   The problem i am having is that no matter what i do, the widget wont stop thinking
   that the screen_name is $tweetid and i keep getting a message to check the user
   name.

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

 *  [Michael](https://wordpress.org/support/users/alchymyth/)
 * (@alchymyth)
 * [13 years, 2 months ago](https://wordpress.org/support/topic/php-inserting-code-into-shortcode-help/#post-3378928)
 * try to change the one line to:
 *     ```
       $tweetcode = '[rotatingtweets screen_name="'.$tweetid.'"]';
       ```
   
 * there might also be an issue with wrongly placed/opened/not closed php tags (?);
   
   to clarify, please repost the code.
 *  [Martin Tod](https://wordpress.org/support/users/mpntod/)
 * (@mpntod)
 * [13 years, 2 months ago](https://wordpress.org/support/topic/php-inserting-code-into-shortcode-help/#post-3378929)
 * Try this instead:
 *     ```
       //this retrieves the author's twitter username
       $tweetid = get_the_author_meta( 'twitter' );
       // Check that rotating tweets is installed and that there is a twitter id
       if (!empty($tweetid) && function_exists('rotatingtweets_display') )  {
           rotatingtweets_display( array (
               'screen_name' => $tweetid
           ));
       }
       ```
   
 *  [Martin Tod](https://wordpress.org/support/users/mpntod/)
 * (@mpntod)
 * [13 years, 2 months ago](https://wordpress.org/support/topic/php-inserting-code-into-shortcode-help/#post-3378931)
 * Good point re: inverted commas. I guess changing to:
 *     ```
       $tweetcode = "[rotatingtweets screen_name='$tweetid']";
       ```
   
 * should work too!
 *  [Martin Tod](https://wordpress.org/support/users/mpntod/)
 * (@mpntod)
 * [13 years, 2 months ago](https://wordpress.org/support/topic/php-inserting-code-into-shortcode-help/#post-3378934)
 * Although I’ve just done some checking – and you do need to check the function
   is there.
 * So something like:
 *     ```
       // this retrieves the author's twitter username
       $tweetid = get_the_author_meta( 'twitter' );
       //this should enter that username unto the required field of the shortcode
       $tweetcode = "[rotatingtweets screen_name='$tweetid']";
       // Check that rotating tweets is installed and that there is a twitter id
       if (!empty($tweetid) && function_exists('rotatingtweets_display_shortcode') )  {
           echo do_shortcode($tweetcode);
       }
       ```
   
 * should also work

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

The topic ‘php inserting code into shortcode help’ is closed to new replies.

## Tags

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

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 4 replies
 * 3 participants
 * Last reply from: [Martin Tod](https://wordpress.org/support/users/mpntod/)
 * Last activity: [13 years, 2 months ago](https://wordpress.org/support/topic/php-inserting-code-into-shortcode-help/#post-3378934)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
