Timothy's Dev Stuff

A collection of code snippets and other developer things.

Create Dynamic Copyright Text in Elementor

This issue came up when creating a template for a WordPress multi-site setup. I needed a way to make sure the copyright year was dynamic along with it automatically pulling the site title while maintaining the theme layout. The solution I came up with was to create a shortcode that only outputs the year. The code to do that is very simple and added to the theme’s functions.php:

function show_current_year() {
    echo date('Y');
}
add_shortcode('the_year', 'show_current_year');

Now in Elementor, we can edit the footer and choose a text widget to hold the copyright. Click the “Dynamic Tags” icon and select “Site Title”. Click the wrench next to site title and expand the advanced menu. Enter the following code in the “Before” field:

© [the_year] — 

This will output a copyright symbol followed by the current year in YYYY format, then an mdash, then the site title.