1

I want to show the "last updated date" on the front of the post and page.
so I add the following code in the functions.php file.

function wpb_last_updated_date( $content ) {
$u_time = get_the_time('U');
$u_modified_time = get_the_modified_time('U');
if ($u_modified_time >= $u_time + 86400) {
$updated_date = get_the_modified_time('F jS, Y');
$updated_time = get_the_modified_time('h:i a');
$custom_content .= '<p class="last-updated" style="text-align:right">Last updated on '. $updated_date . ' at '. $updated_time .'</p>';
}
    $custom_content .= $content;
    return $custom_content;
}

add_filter( 'the_content', 'wpb_last_updated_date' );

It works,but I don`t want to show it on my home page.

How can I do ?

1

You can check for your "home page" at the start of your function by using is_home() and/or is_front_page() and just return original content without date. See is_home vs is_front_page

function wpb_last_updated_date( $content ) {
  if ( is_home() || is_front_page() ) return $content; //homepage return content without date

  // your original function code

}

Alterantively you could embes your add_filter in an if statement

  • ya!!! it works !! – Kenny Dec 20 '18 at 3:02
0

I finally solved the problem !!

function wpb_last_updated_date( $content ) {
if( is_front_page() || is_home() ) {
    return $content;
}
if( is_page(array(1017,927))){  
    return $content;    
}
$u_time = get_the_time('U');
$u_modified_time = get_the_modified_time('U');
if ($u_modified_time >= $u_time + 86400) {
$updated_date = get_the_modified_time('F jS, Y');
$updated_time = get_the_modified_time('h:i a');
$custom_content .= '<p class="last-updated">Last updated on '. $updated_date . ' at '. $updated_time .'</p>';  
}
    $custom_content .= $content;
    return $custom_content;
}
add_filter( 'the_content', 'wpb_last_updated_date' );

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.