$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>filters - Last updated date function|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

filters - Last updated date function

matteradmin9PV0评论

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 ?

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 ?

Share Improve this question asked Dec 19, 2018 at 3:43 cindycindy 1059 bronze badges
Add a comment  | 

2 Answers 2

Reset to default 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

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' );

Articles related to this article

Post a comment

comment list (0)

  1. No comments so far