• Resolved Mayank Kumar

    (@markmemayank)


    Hey,

    I am running a snippet in backend to replace the published date to Last update date.

    Last update feature is working perfectly and that’s fine. But when we are visiting the author profile then it is showing us that the blogs published are 54 years ago.

    The snippet which I am using is:

    function et_last_modified_date_blog( $the_date ) {
        if ( 'post' === get_post_type() ) {
            $the_time = get_post_time( 'His' );
            $the_modified = get_post_modified_time( 'His' );
     
            $last_modified =  sprintf( __( 'Last  updated on %s', 'Divi' ), esc_html( get_post_modified_time( 'M j, Y' ) ) );
            
     
            $date = $the_modified !== $the_time ? $last_modified . '   ' .  $published : $published;
     
            return $date;
        }
    }
    add_action( 'get_the_date', 'et_last_modified_date_blog' );
    add_action( 'get_the_time', 'et_last_modified_date_blog' );

    What could be error and possible solution? Or any alternative snippet I can use.

    Website Link: https://cshub.in/

    • This topic was modified 1 year, 6 months ago by Mayank Kumar.
    • This topic was modified 1 year, 6 months ago by Mayank Kumar.

    The page I need help with: [log in to see the link]

Viewing 3 replies - 1 through 3 (of 3 total)
  • Most likely, whatever front-end code your theme is using to show the post date is expecting a date format and could be doing some extra processing there. To know why that’s happening, we’d need to see the code that’s used to display it.

    If you just want to run this in the backend (admin), you can use an is_admin() check in your filter to ensure that it’s only running on the admin side.

    Thread Starter Mayank Kumar

    (@markmemayank)

    Can you please elaborate it more?

    Thread Starter Mayank Kumar

    (@markmemayank)

    Hey @greenshady , I just took the help of ChatGPT and it get solved.

    Revised snippet is:

    function et_last_modified_date_blog( $the_date, $d, $post ) {
        if ( 'post' === get_post_type( $post ) ) {
            $the_time = get_post_time( 'His', false, $post );
            $the_modified = get_post_modified_time( 'His', false, $post );
            
            if ( $the_modified !== $the_time ) {
                return sprintf( __( 'Last updated on %s', 'Divi' ), esc_html( get_post_modified_time( 'M j, Y', false, $post ) ) );
            }
        }
        return $the_date;
    }
    
    add_filter( 'get_the_date', 'et_last_modified_date_blog', 10, 3 );
    

    Thanks for your reply. I am closing this thread now.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘After adding “Last Update date”, error in date on user profile’ is closed to new replies.