• Resolved bigvibes

    (@bigvibes)


    Hi, I’d like to have the last updated snippet appear only on posts. I saw a previous post regarding this and tried adding the code mentioned there (see below), but it doesn’t seem to work. I tried the new code at the top and at the bottom of the last updated code…

    add_action( ‘wp_head’, function () {

    if ( ! is_single() ) {
        return;
    }
    
    ?>
    <style>
    
    /* css code here */
    
    </style>
    <?php

    } );

    function show_last_modified_date( $content ) {
    $original_time = get_the_time(‘U’);
    $modified_time = get_the_modified_time(‘U’);
    if ($modified_time >= $original_time + 86400) {
    $updated_time = get_the_modified_time(‘h:i a’);
    $updated_day = get_the_modified_time(‘F jS, Y’);
    $modified_content .= ‘

    Last updated: ‘. $updated_day . ”;
    }
    $modified_content .= $content;
    return $modified_content;
    }
    add_filter( ‘the_content’, ‘show_last_modified_date’ );

Viewing 1 replies (of 1 total)
  • Plugin Author Shea Bunge

    (@bungeshea)

    You can achieve this with an if statement check at the beginning of your function:

    function show_last_modified_date( $content ) {
    	if ( 'post' !== get_post_type() ) {
    		return $content;
    	}
    
    	$original_time = get_the_time( 'U' );
    	$modified_time = get_the_modified_time( 'U' );
    	$modified_content = '';
    
    	if ( $modified_time >= $original_time + 86400 ) {
    		$updated_time = get_the_modified_time( 'h: i a' );
    		$updated_day = get_the_modified_time( 'F jS, Y' );
    
    		$modified_content .= '
    
    Last updated: ' . $updated_day;
    	}
    
    	$modified_content .= $content;
    	return $modified_content;
    }
    
    add_filter( 'the_content', 'show_last_modified_date' );
Viewing 1 replies (of 1 total)
  • The topic ‘How to get snippets to show up on Posts only, not pages’ is closed to new replies.