1

I want to create a shortcode function that returns: 2021 - 2022

And then it would update next year automatically.

This is the (broken) code I have so far:

function current_class_year(){
    return date('Y'); // current year
    return date('Y', strtotime('+1 year')); // next year
}
add_shortcode( 'current_class_year', 'current_class_year' );

Thanks for any help.

Lena Shore
  • 45
  • 7
  • Does this answer your question? [How can I combine two strings together in PHP?](https://stackoverflow.com/questions/8336858/how-can-i-combine-two-strings-together-in-php) – El_Vanja May 20 '21 at 15:19
  • 2
    You're looking to combine two strings and then return that. What you have now can't work because `return` terminates the function, so the second line is never executed. – El_Vanja May 20 '21 at 15:20
  • That's the right idea, but it doesn't work in a function when I tried it. Or at least don't know how. – Lena Shore May 20 '21 at 15:22

2 Answers2

2

try this

function current_class_year(){
    return date('Y') .' - '.date('Y', strtotime('+1 year'));
}
add_shortcode( 'current_class_year', 'current_class_year' );
Kashif
  • 480
  • 4
  • 11
1

function current_class_year(){

    return date('Y').' - '.date('Y', strtotime('+1 year')); // Will return : current year - next year

}