Auto Add Dynamic Year in WordPress Post Titles

#6961
  • Resolved Gopi
    Rank Math free

    //* 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 5 years, 6 months ago by Gopi.
Viewing 5 replies - 1 through 5 (of 5 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.

    ​​​​​​

    Gopi
    Rank Math free

    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

    Reference: https://technumero.com/auto-add-dynamic-year-in-wordpress-post-titles/

    • This reply was modified 5 years, 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.

    Gopi
    Rank Math free

    Thanks

    WORK LIKE A CHARM

    Hello,

    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 https://wordpress.org/support/plugin/seo-by-rank-math/reviews/?rate=5#new-post 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.

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

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