Skip to content

Instantly share code, notes, and snippets.

@DustinWStout
Created January 2, 2019 17:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DustinWStout/856fca14c415bb40007a60449d847724 to your computer and use it in GitHub Desktop.
Save DustinWStout/856fca14c415bb40007a60449d847724 to your computer and use it in GitHub Desktop.
WordPress Dynamic Year shortcode. Just add to your functions.php file and use the [year] shortcode in post titles and content.
//* Enable Post Meta Shortcode Support
add_filter( 'single_post_title', 'do_shortcode' );
//* Enable Post Title Shortcode
add_filter( 'the_title', 'do_shortcode' );
//* Current Year In Post Title Shortcode
add_shortcode( 'year' , 'current_year' );
function current_year() {
$year = date("Y");
return "$year";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment