Skip to content

Early-bird lifetime licence: $199 once, for the first 200 buyers only. See the offer

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.

  • Type PHP
  • Runs Where you put the [years_since] shortcode
  • Category Shortcodes
  • Tested with WordPress 7.1
PHP
<?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.

Move your snippets over this afternoon.

Importing changes nothing until you switch over, and your old shortcodes keep working.