Years since shortcode
Type [years_since year="2008"] and it shows how many years have passed, like “18”. For “In business for [years_since year="2008"] years”, always up to date.
<?php
// [years_since year="2008"]
$atts = shortcode_atts( array( 'year' => wp_date( 'Y' ) ), $atts, 'years_since' );
return (string) max( 0, (int) wp_date( 'Y' ) - (int) $atts['year'] );
How to use it
Type [years_since] in a post, a page or a Shortcode block.
In these packs
- Shortcodes: Handy shortcodes for dates, breadcrumbs, buttons, share links, members-only content and more.