Halloween Sale 15% off Ends in See the plans
PHP

Elementor Dynamic Tag: Current Year

Adds a "Current Year" dynamic tag to Elementor Pro so copyright lines and headings update themselves every January.

Don’t have WPIDE yet? Install it on your site

Code

add_action( 'elementor/dynamic_tags/register', function ( $dynamic_tags ) {
    if ( ! class_exists( '\Elementor\Core\DynamicTags\Tag' ) || ! class_exists( '\Elementor\Modules\DynamicTags\Module' ) ) {
        return;
    }

    if ( ! class_exists( 'WPIDE_Elementor_Year_Tag' ) ) {
        class WPIDE_Elementor_Year_Tag extends \Elementor\Core\DynamicTags\Tag {
            public function get_name() {
                return 'wpide-current-year';
            }

            public function get_title() {
                return 'Current Year';
            }

            public function get_group() {
                return 'wpide-site';
            }

            public function get_categories() {
                return array( \Elementor\Modules\DynamicTags\Module::TEXT_CATEGORY );
            }

            public function render() {
                echo esc_html( wp_date( 'Y' ) );
            }
        }
    }

    $dynamic_tags->register_group( 'wpide-site', array( 'title' => 'Site Details' ) );
    $dynamic_tags->register( new WPIDE_Elementor_Year_Tag() );
} );

Notes

Dynamic tags need Elementor Pro. Find the tag under "Site Details" in the dynamic tags list.

How to add this snippet

  1. Install WPIDE on your WordPress site (it is free) and open Code Snippets.
  2. Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
  3. It is added inactive: review the code and settings, then switch it on.

Have a snippet worth sharing?

Publish it to the library from WPIDE or right here. Sign in with any WordPress site that runs WPIDE, free or Pro. Public snippets are reviewed by the WPIDE team before they appear.

Which site should get this snippet?

Enter the address of your WordPress site. WPIDE opens there in a new tab with the snippet ready to review and save.

Remembered in this browser only, so you are asked once.

Report this snippet

Tell the WPIDE team what is wrong: broken code, something harmful, spam or copied work.