Create a Custom Shortcode in WordPress

If you ever get tired of manually updating the year in your footer on your WordPress sites, create a shortcode to update it automatically. This quick tutorial will show you how to create a shortcode so you can insert the text anywhere you’d like.

CODE FOR YOUR FUNCTIONS FILE

<?php
//Allow shortcodes in widgets
add_filter ('widget_text', 'do_shortcode');
//Display current year
function year_shortcode() {
$year = date_i18n('Y'); 
return $year; 
} 
add_shortcode ('year', 'year_shortcode');

// [year] shortcode => 2022
function od_year_shortcode() { return date('Y'); }
add_shortcode('year', 'od_year_shortcode');
?>

Resources

Here are links to the programs and sites I mentioned in the video.

Divi: https://bit.ly/3mun7TN
WordPress: https://wordpress.org/

Want to learn with me?

Check out my digital course, Recipe For A Sales Page on Udemy. This course features my recipe for a sales or landing page and identifies all the ingredients you need to make a compelling page that will capture your reader’s attention and turn them into paying customers.

Disclosure: Some of the links in this post are “affiliate links.” This means if you click on the link and purchase the item, I will receive an affiliate commission.