Created
February 14, 2017 14:50
-
-
Save Cheffheid/002b0a77d035b44d2cc3e0b7c30dc0e9 to your computer and use it in GitHub Desktop.
Age shortcode for WordPress
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function cheffism_age_function($atts) { | |
extract(shortcode_atts(array( | |
'date' => '12/31/1900', // DOB | |
'format' => 'dd/MM/YYYY' // Format, does not currently do anything | |
), $atts)); | |
//explode the date to get month, day and year | |
$date = explode("/", $date); | |
//get age from date or birthdate | |
$age = (date("md", date("U", mktime(0, 0, 0, $date[1], $date[0], $date[2]))) > date("md") ? ((date("Y") - $date[2]) - 1) : (date("Y") - $date[2])); | |
return $age; | |
} | |
add_shortcode('age', array( $this, 'cheffism_age_function') ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment