Display current Month in wordpress title

#324356
  • Resolved Jitendra Kumar Singh
    Rank Math free

    Hello Support,

    Is there any way I can display current month and current year in my title. Like I can display in SEO title but I want to display in my title as well.

Viewing 5 replies - 1 through 5 (of 5 total)
  • Hello,

    Thank you for contacting Rank Math support today and bringing your concern to our attention.

    Unfortunately, Rank Math’s variable won’t work on your title. You may need to make use of shortcodes.

    Here’s a piece of code that you can insert into your theme’s functions.php file:

    add_shortcode( 'date_year' , 'current_date_year' );
    function current_date_year() {
        return date("Y");
    }
    add_filter( 'the_title', 'do_shortcode' );

    When that code is active on your site, you can use [date_year] to display the year.

    Hope that helps and please do not hesitate to let us know if you need our assistance with anything else.

    Thanks Jeremy.

    This is working and showing the year. Can you please tell me how I can show current month too?

    I dont know if I am wrong or not but I modified the code

    add_shortcode( 'date_year' , 'current_date_year' );
    function current_date_year() {
        return date("Y");
    }
    
    add_shortcode( 'date_month' , 'current_date_month' );
    function current_date_month() {
        return date("M");
    }
    add_filter( 'the_title', 'do_shortcode' );

    I am getting year and initials of month like Jan.

    How can I display full month?

    Got it fixed.

    add_shortcode( 'date_year' , 'current_date_year' );
    function current_date_year() {
        return date("Y");
    }
    
    add_shortcode( 'date_month' , 'current_date_month' );
    function current_date_month() {
        return date("F");
    }
    add_filter( 'the_title', 'do_shortcode' );
    

    Thanks Jeremy

    Hello,

    We are super happy that you have resolved your issue.

    If you 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)

You must be logged in to reply to this ticket.