• Hey guys,

    Hope all is well!

    Enabling a last updated date to posts is easily done via customization.

    However, I want this last updated date to be present on pages as well.

    I assume this could be easily done by editing the right file to have the condition to apply to pages too, but I’m just not sure what file that is.

    Would you be able to walk me through this, please?

    Thanks!

Viewing 7 replies - 1 through 7 (of 7 total)
  • Hi @worldwideg ,

    You can’t do this only via customization. You can achieve what you want only with custom code.

    For this you need to modify functions.php. For that, you need to set a child theme, here are the steps: https://docs.themeisle.com/article/985-how-to-create-a-child-theme-for-neve#:~:text=Install%20child%20theme,-1&text=Download%20the%20basic%20child%2Dtheme,CSS%20panel%20in%20the%20Customizer.

    In your child theme, go to Theme File Editor > functions.php and put this custom code there.

    function my_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 entry-meta">Last updated on '. $updated_date. ' at '. $updated_time.'</p>';

    }

    $custom_content.= $content;

    return $custom_content;

    }

    add_filter( 'the_content', 'my_last_updated_date' );

    Tell me if this solves your problem.

    Kind regards,

    Denis

    Thread Starter worldwideg

    (@worldwideg)

    Thanks for the help!

    So, I installed the child theme but adding the code in the functions.php did nothing there. However, it might be that I need to clear cache.

    But I also tried adding the code in functions.php in the main theme. This added a last updated text, but not as intended.

    1. It appeared not only on pages, but also on posts where I already have it
    2. It didn’t appear where it is supposed to be. On posts, it is in the .nv-post-cover and this is where I would want it added on the pages as well.

    This is for posts, which now has double last updated (the one under the table of content is the one that got added with the above code):

    https://ibb.co/6ccvtJgt

    And this is for pages:

    https://ibb.co/sp3r91M8

    • This reply was modified 9 months, 3 weeks ago by worldwideg.

    Hi there,

    Unfortunately obtaining that it’s a bit more difficult, and it can require more advanced custom code.

    You can try instead, looking for an alternative solution. For example, you can try this plugin https://ww.wp.xz.cn/plugins/wp-last-modified-info/ and add their “Modified date” block in the page where you want this to be displayed https://vertis.d.pr/i/Fc0M8T https://vertis.d.pr/i/HFqL3x

    Hope this helps.

    Kind regards,

    Rodica

    Thread Starter worldwideg

    (@worldwideg)

    Hey,

    I don’t mind advanced customization. My site is already heavily customized.

    I can get this fixed with the help of ChatGPT but figured it would be easier to get it fixed here since you know the code. And perhaps less risky of breaking my site.

    I don’t want to install any plugin for it.

    Hi @worldwideg ,

    I managed to find a way to display the latest update date just only on the pages. I tried a lot of things to display it in the cover, nothing worked.

    Here is a custom code to add in functions.php:

    function my_last_updated_date( $content ) {
    if ( ! is_page() ) {
    return $content;
    }

    $u_time = get_the_time('U');
    $u_modified_time = get_the_modified_time('U');
    $custom_content = '';

    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 entry-meta">Last updated on '. $updated_date. ' at '. $updated_time.'</p>';
    }

    $custom_content .= $content;
    return $custom_content;
    }

    add_filter( 'the_content', 'my_last_updated_date' );

    Hope I was helpful!

    Denis

    Thread Starter worldwideg

    (@worldwideg)

    Really appreciate the help.

    I really want it displayed in the cover though. I’ll try to figure it out. It’s weird because you’d think if there’s a code where it’s put in the post, you should be able to just find that code and then also include pages in that code.

    Another weird thing when adding the code you provided me with is that some pages don’t get the last updated added for some reason. Well, I only know of one page that doesn’t get it:

    https://worldwidegamblers.com/casino/sweepstakes/reviews/wow-vegas/

    But still. I’m puzzled why every other page gets it but not this one.

    Hi @worldwideg ,

    Make sure to have all the caches purged. There can be multiple cases:

    1. Browser Cache: Clear your browser’s cache to ensure you’re not seeing an outdated version. 
    2. WordPress Cache: If you have a caching plugin (like WP Rocket, WP Super Cache, or WP Fastest Cache), use its feature to purge the cache. 
    3. Server Cache: Some hosting providers use server-level caching; check your hosting control panel for options to clear it. 

    I’ll try to figure out meanwhile how can I solve your request with the cover. Tell me if what I told you worked.

    Denis

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

The topic ‘Adding last updated date to pages’ is closed to new replies.