There is a Yoast Seo plugin that allows you to add %% currentyear %% and %% currentmonth %% variables to your pages title, as well as add your variables via functions.php

The task is to print the month and year into a title (and the month will be a constant value, and the year is variable) according to the following logic: For example, the title: "Rest in Bulgaria in May% the variable of the year%" this year, then we derive the next year. If not passed or still goes, we derive the current year.

How to implement it correctly in functions.php

I would be very grateful for the help.

Closed due to the fact that the essence of the issue is incomprehensible by the participants of Streletz , user194374, aleksandr barakin , Bald , D-side 11 Jul '16 at 12:18 .

Try to write more detailed questions. To get an answer, explain what exactly you see the problem, how to reproduce it, what you want to get as a result, etc. Give an example that clearly demonstrates the problem. If the question can be reformulated according to the rules set out in the certificate , edit it .

    1 answer 1

    Specifying this plug-in in question is only misleading, since the authors do not implement these substitutions ( %%currentyear%% , %%currentmonth%% ) through functions.php and pass the parameter to the substitutions (what you need) will not work.

    The easiest way is to find the functions.php file among your theme files, add something like this there:

     function validYearForMonth($month) { $month = intval($month); $currentMonth = date('n'); $year = date('Y'); if ($month < $currentMonth) { $year++; } return $year; } 

    And now in the theme files you can call:

     <?=validYearForMonth(5);?> 

    In the parameter you pass the number of the month (starting from 1). So, in the example passed in May. For the current moment (June 2016) 2017 will be returned.

    • Thank you very much. And how to make the current year output for the current month not yet finished? - Igor Dobrenkov
    • So if you pass the current month, then the year will also be current. The following is only for the past. - Gino Pane