• Resolved bayonjoset

    (@bayonjoset)


    Hi,

    I have added a PHP function shown in a blog to my functions.php (child theme) to display last updated time to my blog posts. But it started showing the last updated time to my Home page. I tried a few codes to skip home page like if (is_page(2020)) return; but didn’t solve the issue. How can I only display this for posts?

    Another thing; I want the last updated date to display in Google Results. What is the best way to do it? I saw this thread discussing that issue, but I couldn’t understand which one I should change.

    The code I added to display updated time:

    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' );
    • This topic was modified 6 years ago by bayonjoset.

    The page I need help with: [log in to see the link]

Viewing 6 replies - 1 through 6 (of 6 total)
  • Thread Starter bayonjoset

    (@bayonjoset)

    Hi again,

    SO I found this support document from theme documentation. I changed my current code with this. It displayed Author name, category, published and updated date in bullet points. SO I changed the styling according to my knowledge. Given below. Do you this will do the trick. Currently, it’s displaying okay.

    I will change it if it’s harmful.

    // Add Last Modified Date to Single Blog Post Meta
    function prefix_single_meta() {
    	global $post;
    	?>
    		
    		<p class="last-updated" <?php oceanwp_schema_markup( 'modified_date' ); ?>>Last updated on <span aria-hidden="true"><?php echo get_the_modified_date(); ?></p>
    		<p class="last-updated"<?php oceanwp_schema_markup( 'publish_date' ); ?>> - Published on <i aria-hidden="true"></i><?php echo get_the_date(); ?></p>
    	<?php
    }
    add_filter('ocean_blog_single_meta','prefix_single_meta');
    
    function prefix_entry_meta() {
    	?>
    		<ul>
    		<li<?php oceanwp_schema_markup( 'author_name' ); ?>><i aria-hidden="true"></i><?php echo the_author_posts_link(); ?></li>
    		<li><i aria-hidden="true"></i><?php the_category( ' <span>/</span> ', get_the_ID() ); ?></li>
    		<li<?php oceanwp_schema_markup( 'modified_date' ); ?>><span aria-hidden="true"><?php echo get_the_modified_date(); ?></li>
    		<li<?php oceanwp_schema_markup( 'publish_date' ); ?>><i aria-hidden="true"></i><?php echo get_the_date(); ?></li>
            </ul>
    	<?php
    }
    add_filter('ocean_blog_entry_meta','prefix_entry_meta');
    Amit Singh

    (@apprimit)

    Hello,

    OceanWP has settings to display the modified date. Kindly go to Customize > Blog > Single or Entry > Elements Positioning and enable the modified date option.

    Thread Starter bayonjoset

    (@bayonjoset)

    Hi Amit,

    Thanks man. I saw the option. So should I remove the code from functions.php? And is this enough for Google to display the updated date in search results.?

    Really appreciate your help.

    Amit Singh

    (@apprimit)

    Yes, you can remove your code. It will work properly.

    Thread Starter bayonjoset

    (@bayonjoset)

    Okay mate, thanks for the help.

    Amit Singh

    (@apprimit)

    You’re welcome!

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

The topic ‘Post updated date’ is closed to new replies.