Change %currentdate% timing to update on post meta

#644220
  • Resolved Is It Blogging
    Rank Math free

    Hello, I want to change the timing of %currentdate% when adding it to the Post Meta Title and Description. The %currentdate% changes to the current date at 12:00 a.m., I think. But I want it to automatically change at 2:00 PM in the morning.

    I tried getting code for this using Chat GPT and that did some help it was working but it created some conflict and removed the post title from the meta and showed only the date.

    Chat GPT gave me this code –

    // Function to dynamically generate meta title
    function custom_meta_title($title) {
    // Check if the current time is after 2:00 PM (14:00)
    if (strtotime(current_time('H:i')) >= strtotime('14:00')) {
    // It's 2:00 PM or later, so set the meta title to the current day's date
    $title = date('j F Y') . ' - Your Custom Title'; // Replace 'Your Custom Title' with your desired title
    } else {
    // It's before 2:00 PM, so set the meta title to the previous day's date
    $title = date('j F Y', strtotime('-1 day')) . ' - Your Custom Title'; // Replace 'Your Custom Title' with your desired title
    }
    return $title;
    }
    add_filter('rank_math/frontend/title', 'custom_meta_title');

    But, this caused some conflict and that post title disappeared. Please throw some light on how can I achieve it.

    Thanks –

Viewing 1 replies (of 1 total)
  • Hello,

    Thank you for your query and we are so sorry about the trouble this must have caused.

    We cannot modify that variable but the code you shared we did test and we can see it’s outputting the date correctly in the title based on the conditions you set.

    Now, if you want to add the date before the title and only append to it you can update the code with the following:

    
    add_filter( 'rank_math/frontend/title', function( $title ) {
    	if (strtotime(current_time('H:i')) >= strtotime('14:00')) {
    		$title = date('j F Y') . ' - ' . $title;
    	} else {
    		$title = date('j F Y', strtotime('-1 day')) . ' - ' . $title;
    	}
    
    	return $title;
    });
    

    Hope this helps get you the desired result.

    Don’t hesitate to get in touch if you have any other questions.

    Hello,

    Since we did not hear back from you for 15 days, we are assuming that you found the solution. We are closing this support ticket.

    If you still need assistance or any other help, please feel free to open a new support ticket, and we will be more than happy to assist.

    Thank you.

Viewing 1 replies (of 1 total)

The ticket ‘Change %currentdate% timing to update on post meta’ is closed to new replies.