I need to display the current year in Wordpress, now this is already being done in the footer template using php:

<?php echo date('Y'); ?> 

The site in question is for a car dealer. So there are many year model references in the page/post content ie.

<h1>2013 Volkswagen Polo</h1> 

All of these need updated on the first of January each year. However the php code doesn't work within the page/post content, only in template files. So I need a different way to do this.

Any ideas?

Thanks in advance
Willem

3

3 Answers

Why don't you create the simple shortcode function for this purpose?

function currentYear( $atts ){ return date('Y'); } add_shortcode( 'year', 'currentYear' ); 

Then you will be able to put [year] to anywhere in the content area.

1

A little modification of previous answer which also works fine:

in functions.php:

<?php function currentYear(){ return date('Y'); } ?> 

then in footer.php (or anywhere as mentioned before):

<p>&copy; 2016-<?php echo currentYear(); ?> <a href="#">your_homepage_title</a></p> 

There is a plugin in wordpress which enables php code inside your post or content which will render perfectly and give you resul. search for exec php plugin in wordpress and add into your wordpress.

2

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy