Title: shortcode attribute default value post-&gt;ID
Last modified: August 20, 2016

---

# shortcode attribute default value post->ID

 *  [ryanve](https://wordpress.org/support/users/ryanve/)
 * (@ryanve)
 * [15 years ago](https://wordpress.org/support/topic/shortcode-attribute-default-value-post-id/)
 * I have a shortcode `[user-profile]` where the author ID is the attribute. I’d
   like to make it so that if no ID is specified `[user-profile]` defaults to post
   author, and when an ID _is_ specified, like `[user-profile id="47"]`, it uses
   that ID. The shortcode function right now is like this:
 *     ```
       function user_profile( $atts, $content = null ) {
       	extract(shortcode_atts(array('id' => ''), $atts));
       	include ('user-profile.php');
       	return $user_hcard;
       	}
       ```
   
 * …which works only when an ID is specified.
    ([user-profile.php code is here](http://dev.airve.com/code/user-profile_20110606.txt))
   How can I set the default to be the $post->ID ?

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

 *  [Michael](https://wordpress.org/support/users/alchymyth/)
 * (@alchymyth)
 * [15 years ago](https://wordpress.org/support/topic/shortcode-attribute-default-value-post-id/#post-2120246)
 * have you read the codex: [http://codex.wordpress.org/Shortcode_API](http://codex.wordpress.org/Shortcode_API)
 *  Thread Starter [ryanve](https://wordpress.org/support/users/ryanve/)
 * (@ryanve)
 * [15 years ago](https://wordpress.org/support/topic/shortcode-attribute-default-value-post-id/#post-2120267)
 * Of course 🙂
    I already tried
 *     ```
       extract(shortcode_atts(array('id' => $post->ID), $atts));
       ```
   
 * but no dice.
 *  [Michael](https://wordpress.org/support/users/alchymyth/)
 * (@alchymyth)
 * [15 years ago](https://wordpress.org/support/topic/shortcode-attribute-default-value-post-id/#post-2120277)
 * as this is in functions.php, you may need to use `global $post` right at the 
   beginning of the function.
 *  Thread Starter [ryanve](https://wordpress.org/support/users/ryanve/)
 * (@ryanve)
 * [15 years ago](https://wordpress.org/support/topic/shortcode-attribute-default-value-post-id/#post-2120605)
 * This works—killer! Thanks =)
 *     ```
       function user_profile( $atts, $content = null ) {
       	global $post;
       	extract(shortcode_atts(array('id' => ''), $atts));
       	include ('user-profile.php');
       	return $user_hcard;
       	}
       ```
   

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

The topic ‘shortcode attribute default value post->ID’ is closed to new replies.

## Tags

 * [$post->id](https://wordpress.org/support/topic-tag/post-id/)
 * [attribute](https://wordpress.org/support/topic-tag/attribute/)
 * [author ID](https://wordpress.org/support/topic-tag/author-id/)
 * [id](https://wordpress.org/support/topic-tag/id/)
 * [shortcode](https://wordpress.org/support/topic-tag/shortcode/)

 * 4 replies
 * 2 participants
 * Last reply from: [ryanve](https://wordpress.org/support/users/ryanve/)
 * Last activity: [15 years ago](https://wordpress.org/support/topic/shortcode-attribute-default-value-post-id/#post-2120605)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
