Auto Add Dynamic Year in WordPress Post Titles

  • Resolved Gopi

    //* Shortcode to display the current year in WordPress
    //* shortcode: [year]
    add_shortcode( ‘year’ , ‘current_year’ );
    function current_year() {
    $year = date(“Y”);
    return “$year”;

    Am using this code to add dynamic year wordpress post title. so i want to replicate the same in Rank Math snippet title also, but its not reflecting. how to do that?
    or Rankmath has any shortcode to use directly in WordPress title and snippet.

    Edit currentyear works only snipper

    • This topic was modified 6 months ago by Gopi.
Viewing 6 replies - 1 through 6 (of 6 total)
  • Hello,

    Thank you for contacting Rank Math today.

    Rank Math comes with its own variable to get the year, you can make use of the variable %currentyear% within the Rank Math metabox to achieve the same result.

    I hope this info helps. Thank you.


    My Issue is different. i want to use %currentyear% in post title is it possible?

    or i have created shortcode [year] which is working in post title but not reflecting in meta box


    • This reply was modified 6 months ago by Gopi.

    Hi Gopi,

    Thanks for the clarification.

    Yes you can use the same Rank Math variable on your post title but you will need to hook into the_title filter, you can use the following code in your functions.php file:

    function my_custom_RM_title_replace_vars( $title, $id = null ) {
        return RankMath\Helper::replace_vars( $title );
    add_filter( 'the_title', 'my_custom_RM_title_replace_vars', 10, 2 );

    I hope this info helps. Thank you.




    We are super happy that this resolved your issue. If you have any other questions in the future, know that we are here to help you.

    If you don’t mind me asking, could you please leave us a review (if you haven’t already) on about your overall experience with Rank Math? We appreciate your time and patience.

    If you do have another question in the future, please feel free to create a new forum topic, and it will be our pleasure to assist you again.

    Thank you.


    I have updated the sensitive data as requested. Can you please check further?

    Thank you.

Viewing 6 replies - 1 through 6 (of 6 total)

The ticket ‘Auto Add Dynamic Year in WordPress Post Titles’ is closed to new replies.