• Resolved ImageJaneBarnes

    (@janebarnes)


    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?

Viewing 12 replies - 1 through 12 (of 12 total)
  • There is condition for home page – see https://codex.wordpress.org/Conditional_Tags
    just !is_home()

    Thread Starter ImageJaneBarnes

    (@janebarnes)

    Thank you, much appreciated.

    Thread Starter ImageJaneBarnes

    (@janebarnes)

    Hi Again,

    Sorry, I am still not sure what to add (I assume it goes Tags section?)

    Is it: !is_home()

    Cheers.

    Plugin Author ImageShea Bunge

    (@bungeshea)

    @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.

    Thread Starter ImageJaneBarnes

    (@janebarnes)

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

    Thread Starter ImageJaneBarnes

    (@janebarnes)

    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.

    Plugin Author ImageShea Bunge

    (@bungeshea)

    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'  );
    Thread Starter ImageJaneBarnes

    (@janebarnes)

    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.

    Thread Starter ImageJaneBarnes

    (@janebarnes)

    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?

    Thread Starter ImageJaneBarnes

    (@janebarnes)

    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.

    Plugin Author ImageShea Bunge

    (@bungeshea)

    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.

    Thread Starter ImageJaneBarnes

    (@janebarnes)

    Hi Shaw, I gave up on it ages ago and now use a plugin instead. Thanks.

Viewing 12 replies - 1 through 12 (of 12 total)

The topic ‘Remove snippet from home page?’ is closed to new replies.