Title: How to Reference/Echo Attribute from Another PHP Function
Last modified: August 22, 2016

---

# How to Reference/Echo Attribute from Another PHP Function

 *  [rfmurphy81](https://wordpress.org/support/users/rfmurphy81/)
 * (@rfmurphy81)
 * [11 years, 9 months ago](https://wordpress.org/support/topic/how-to-referenceecho-attribute-from-another-php-function/)
 * I am now looking to display JUST the view count and duration values for the video
   on the home/list pages (via loop.php) but having difficulty determining the appropriate
   PHP code to do this.
 * Here is the function that I’ve been using successfully for the post view:
 * > add_shortcode(‘yt’, ‘getYoutubeDetails’);
   > function getYoutubeDetails($atts) {
   >  extract(shortcode_atts(array( ‘video’ 
   > => ” ), $atts));
   >  // Get YouTube data via the API
   >  $JSON = file_get_contents(“[https://gdata.youtube.com/feeds/api/videos?q=$video&alt=json&#8221](https://gdata.youtube.com/feeds/api/videos?q=$video&alt=json&#8221););
   > $JSON_Data = json_decode($JSON); $views = $JSON_Data->{‘feed’}->{‘entry’}[0]-
   > >{‘yt$statistics’}->{‘viewCount’}; $views = number_format($views); $duration
   > = $JSON_Data->{‘feed’}->{‘entry’}[0]->{‘media$group’}->{‘yt$duration’}->{‘seconds’};
   >  echo “<iframe width=\”1280\” height=\”720\” src=\”//www.youtube.com/embed/
   > $video?showinfo=0&rel=0&modestbranding=1&theme=light&iv_load_policy=3&autohide
   > =1&enablejsapi=1\” frameborder=\”0\” allowfullscreen></iframe>”;
   >  echo “**Views:**
   > $views**Duration:** “; echo sec2hms($duration); echo “
   > “;
   >  }
 * Within my post content, I tag my videos as [yt video=”VIDEOID”]. I was hoping
   I could get the specific attribute for views/duration by using: ‘<?php echo GetYoutubeDetails(
   $views) ?>’ in loop.php, but that doesn’t seem to work. Is there a way to structure
   this to pull in a specific attribute within the function? Would it be able to
   leverage the value being passed into the video attribute of the shortcode that’s
   already in the post content?
 * I’d prefer to tap into the existing shortcode already in the post content (so
   I’m not having to maintain it two or more different places). However, if there
   isn’t a way to echo the value of an existing function for a particular post in
   loop.php, I was thinking it may need to get handled via a custom field somehow.
 * Any suggestions for how to tackle this issue?

The topic ‘How to Reference/Echo Attribute from Another PHP Function’ is closed 
to new replies.

## Tags

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

 * In: [Hacks](https://wordpress.org/support/forum/plugins-and-hacks/hacks/)
 * 0 replies
 * 1 participant
 * Last reply from: [rfmurphy81](https://wordpress.org/support/users/rfmurphy81/)
 * Last activity: [11 years, 9 months ago](https://wordpress.org/support/topic/how-to-referenceecho-attribute-from-another-php-function/)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
