Implement today’s date using the Elementor shortcode

If you prefer the code-based approach, you can actually create your own shortcode with just a few lines of code. Personally, this is my preferred method because it gives you the flexibility to insert the current date into any part of the content, not just the widget area.

You can put this code in:

Your child theme’s functions.php file

Your custom plugin

I’ll show you how to do this using functions.php, as it’s the simplest method – if you change your theme, you just need to remember to copy this code.

To create the shortcode, simply add this code to your functions.php file:

function displayTodaysDate( $atts )

{

   return date(get_option(‘date_format’));

}

add_shortcode( ‘datetoday’, ‘displayTodaysDate’);

The shortcode will use the same date format you set in Settings → General.

After adding the code, you can use the [datetoday] shortcode in the WordPress editor or the Elementor shortcode module:

Display today’s date using code.

Note – This section is really only for those with at least some understanding of code and WordPress themes. If you are a beginner, I recommend sticking with the first two methods.

Finally, if you’re willing to personally work with your theme’s template files, you can also insert today’s date anywhere on your WordPress website using just one line of PHP code.

You can choose from two different code snippets:

<?php echo date(get_option(‘date_format’)); ?>

The code snippet above displays the current date based on your WordPress settings, just like a shortcode.

However, you can also specify the date format as * using the following code:

<?php echo date(‘l jS F Y’); ?>


Discover more from Fusionveil

Subscribe to get the latest posts sent to your email.

Other Articles

Leave a Reply