Title: Creating a Year shortcode
Last modified: August 19, 2016

---

# Creating a Year shortcode

 *  Resolved [elhashbrown](https://wordpress.org/support/users/elhashbrown/)
 * (@elhashbrown)
 * [15 years, 1 month ago](https://wordpress.org/support/topic/creating-a-year-shortcode/)
 * I am trying to create a shortcode called ‘year’ that I can place within pages
   as I have documents which should always refer to the current year. I have used
   the following in my functions.php:
 *     ```
       function year_shortcode() {
       	$year = the_time('Y');
       	return $year;
       }
   
       add_shortcode('year', 'year_shortcode');
       ```
   
 * This brings the current year into the page but it sits at the top of the div 
   rather than inline with the text. I’m wondering if the_time is being echoed despite
   the fact I used return? Can I use &echo=0 somewhere?

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

 *  [Michael](https://wordpress.org/support/users/alchymyth/)
 * (@alchymyth)
 * [15 years, 1 month ago](https://wordpress.org/support/topic/creating-a-year-shortcode/#post-2036312)
 * this is because `the_time()` directly outputs the time;
 * use `get_the_time()` instead: [http://codex.wordpress.org/Function_Reference/get_the_time](http://codex.wordpress.org/Function_Reference/get_the_time)
 * both of these wordpress functions refer to the published **time of the post**.
 * for the current time, try [http://php.net/manual/en/function.date.php](http://php.net/manual/en/function.date.php)
 * this might do what you want; example:
 *     ```
       function year_shortcode() {
       	$year = date('Y');
       	return $year;
       }
   
       add_shortcode('year', 'year_shortcode');
       ```
   
 *  Thread Starter [elhashbrown](https://wordpress.org/support/users/elhashbrown/)
 * (@elhashbrown)
 * [15 years, 1 month ago](https://wordpress.org/support/topic/creating-a-year-shortcode/#post-2036363)
 * That’s got it. Thank you.

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

The topic ‘Creating a Year shortcode’ is closed to new replies.

## Tags

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

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 2 replies
 * 2 participants
 * Last reply from: [elhashbrown](https://wordpress.org/support/users/elhashbrown/)
 * Last activity: [15 years, 1 month ago](https://wordpress.org/support/topic/creating-a-year-shortcode/#post-2036363)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
