Create a shortcode to display the current year

Home » Snippets » Create a shortcode to display the current year
0

Created with:

Visibility: 

public

Creator: Alex

Customize with WPTurbo AI
X

Add Snippet To Project

New Project
Add To Existing Project
					<?php
/**
 * Plugin Name: Current Year Shortcode
 * Description: A shortcode to display the current year.
 * Version: 1.0
 * Author: Alex
 * Author URI: https://wpturbo.dev
 * Text Domain: wpturbo
 */

// Prevent direct access to the file
defined( 'ABSPATH' ) or die( 'No script kiddies please!' );

// Register shortcode to display the current year
// Place the [current_year] shortcode on your website

function wpturbo_current_year_shortcode() {
    return date('Y');
}
add_shortcode('current_year', 'wpturbo_current_year_shortcode');
				

To use this plugin, you need to do the following:

Once the plugin is activated, you can use the [current_year] shortcode anywhere in your posts, pages, or widgets to display the current year.

The plugin header comment at the beginning of the file is necessary for WordPress to recognize it as a plugin. It includes the plugin name, description, version, author name, and author URI. The Text Domain is used for internationalization purposes, allowing the plugin to support translations.

I've also included a security check defined( 'ABSPATH' ) or die( 'No script kiddies please!' ); to prevent direct access to the plugin file, which is a best practice for WordPress development.

Register an account to save your snippets or go Pro to get more features.