Custom Plugin to show age today in a shortcode from date of birth
Download as a zip and install as a plugin
usage [age dob="12 july 1988"]
| <?php | |
| /* | |
| Plugin Name: Age Shortcode | |
| Plugin URI: https://fullworks.net | |
| Description: Shortcode [age dob="28 feb 1971"] display age based on dob | |
| Version: 0.1 | |
| Author: Alan | |
| */ | |
| add_shortcode( 'age', function ( $atts ) { | |
| $a = shortcode_atts( | |
| array( | |
| 'dob' => '28 feb 1971', | |
| ), | |
| $atts ); | |
| $birthdate = new DateTime( date( "Y-m-d", strtotime( $a['dob'] ) ) ); | |
| $today = new DateTime( date( "Y-m-d" ) ); | |
| $age = $birthdate->diff( $today )->y; | |
| echo $age; | |
| } ); |