admin管理员组文章数量:1130349
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 badges2 Answers
Reset to default 1You 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' );
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 badges2 Answers
Reset to default 1You 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' );
本文标签: filtersLast updated date function
版权声明:本文标题:filters - Last updated date function 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://it.en369.cn/questions/1749082945a2313331.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。


发表评论