This code creates a WordPress shortcode, [current_year]
, that automatically displays the current year in posts, pages, or widgets, eliminating the need for manual year updates and ensuring content stays relevant and timely.
/** * Shortcode to display the current year. * * This shortcode outputs the current year when used, allowing for dynamic date display * within posts, pages, or widgets without manual updates. * * Usage: [current_year] * * @return string The current year. */ function display_current_year_shortcode() { return date('Y'); } // Register the shortcode with WordPress add_shortcode('current_year', 'display_current_year_shortcode');