Display today's date in WordPress using PHP

I’m having trouble displaying the current date across different WordPress templates. When I use this function:

<?php echo current_time('j \d\e F \d\e Y'); ?>

It works perfectly on my homepage and shows something like “04 de novembro de 2017” which is exactly what I want since my site is in Portuguese.

However, when I try to use the same code on individual pages, single posts, or archive pages, it displays the post creation date instead of today’s date.

I need a way to consistently show the current date in the format “04 de novembro de 2017” regardless of which page type I’m on. What’s the best approach to achieve this in WordPress?

This usually happens because of WordPress’s template hierarchy and how themes handle date contexts. Had the same headache building a multilingual site last year. Skip current_time() since template logic can mess with it. Use PHP’s native date() with WordPress timezone settings instead: <?php echo date_i18n('j \d\e F \d\e Y', current_time('timestamp')); ?>. The date_i18n() function follows your WordPress locale while current_time('timestamp') gets the actual current time. This combo avoids theme interference since it doesn’t rely on post context. Just make sure your WordPress timezone is set right in Settings > General first.

I’ve hit this exact problem before - it’s usually template conflicts or caching issues. The current_time() function should work everywhere, but themes sometimes mess with date functions on certain pages. Wrap your code in a custom function instead. Drop this in your functions.php: php function get_todays_date() { return current_time('j \d\e F \d\e Y'); } Then just use <?php echo get_todays_date(); ?> in your templates. Fixed it for me every time. Also check for any date plugins that might filter output on specific page types.

yeah, super strange! current_time() shoud work for server date. maybe yer theme or some plugin is interfering. give date('j \d\e F \d\e Y') a shot and see if it helps!

This topic was automatically closed 4 days after the last reply. New replies are no longer allowed.