Remove snippet from home page?
-
Hi, I am using the plugin to have ‘last updated’ on my posts but want to remove it from the home page. Is this possible, please?
-
There is condition for home page – see https://codex.wordpress.org/Conditional_Tags
just !is_home()Thank you, much appreciated.
Hi Again,
Sorry, I am still not sure what to add (I assume it goes Tags section?)
Is it: !is_home()
Cheers.
@janebarnes: not in the tags section – you need to add it as part of your snippet code.
If you give me an example, I can show you where it might go.
Ah, I just am not getting this it seems! Thanks for your help.
Here is the code: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”>Last updated on ‘. $updated_date . ‘ at ‘. $updated_time .'</p>’;
}$custom_content .= $content;
return $custom_content;
}
add_filter( ‘the_content’, ‘wpb_last_updated_date’ );It displays as Last updated with the date as well as the time, is there something I can remove in the code to just display the date? Please. I don’t think the time is needed at all.
Hi Jane,
You would modify it like this to have it only run on the homepage and not display the time:
function wpb_last_updated_date( $content ) { if ( ! is_home() ) return; $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' ); $custom_content .= '<p class="last-updated">Last updated on '. $updated_date . '</p>' ; } $custom_content .= $content; return $custom_content; } add_filter( 'the_content' , 'wpb_last_updated_date' );Hi Shea,
I added that code completely and it returned a fatal error?Luckily the snippets plugin does warn and not just save the changes, any other clues welcomed.
Cheers.
I have worked out how to remove the actual time of the last updated, but cannot work out how to remove it from my home page?
Hi Shea, I am still trying to find the correct code to show last updated on posts and to remove it from the home page? Please.
Hi Jane,
If you’re able to post your updated code, then I can take a look and see how to modify it. It’s a little difficult to help without knowing what code you are currently using.
Hi Shaw, I gave up on it ages ago and now use a plugin instead. Thanks.
The topic ‘Remove snippet from home page?’ is closed to new replies.