Answer a question

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

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.

Logo

WordPress社区为您提供专业的建站知识与服务支持,提供一步到位的镜像安装和wordpress主题与插件支持

更多推荐