Hi there,
I am looking to display the last updated date close the articles’ date of creation. I found this code on the net (here https://www.wpbeginner.com/wp-tutorials/display-the-last-updated-date-of-your-posts-in-wordpress/) :
******************************************************
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’ );
**************************************************************
The above code is to be implemented in the functions.php main theme file.
And my question is : what would be the correct code to implement in functions.php child theme ?
Thanks in advanced :).
Hi,
You could try something like this instead
– https://forum.tagdiv.com/topic/post-last-updated/
In the topic the solution is to replace the theme code but you could add it next to it.
In this example I will use post template style 1 -> loop-single-1.php
– https://www.screencast.com/t/KpcPUqFQ5iC
Direct result is this – https://www.screencast.com/t/4avlf8Mws9
With some CSS – https://www.screencast.com/t/aWKxtrKQDA
.the-modified-date {
display:inline-flex;
}
Code link here for convenience – https://pastebin.com/vCsS4CFf
Of course you can style it further or position it differently if needed.
Thanks
Thanks for the tip. I have simply copied the full loop-single.php in my child theme, then I addded the code line you sugested, and it works.
Yet I guess I don’t have to copy the full loop-single.php in the child theme. What would be the shortest code to implement in the loop-single.php of the child theme ?
Many thanks in advanced :).
What you did is correct. You need to copy the file in the child theme, then modify it. Maintain the same directory path to the file when copying files from various theme folders
– https://forum.tagdiv.com/the-child-theme-support-tutorial/
The files that are supported by the child theme can be modified in it. Once the child theme is active the files will be served from it, not the main theme.
Using a child theme is considered a safe way to modify theme files without losing changes when the main theme is updated. Some more useful information here
– https://www.wpbeginner.com/beginners-guide/wordpress-child-theme-pros-cons/
– https://wpapprentice.com/blog/wordpress-child-theme-need-one/
Is this still accurate?
You say to look in loop-single-X.php for this.
<div class="td-module-meta-info">
<?php echo $td_mod_single->get_author();?>
<?php echo $td_mod_single->get_date(false);?>
<?php echo $td_mod_single->get_views();?>
<?php echo $td_mod_single->get_comments();?>
</div>
This text doesn’t appear in that php file. It’s in single_templateX.php file.
So, which one does it go in?
The post says to put it in loop but that code isn’t in loop.
Thx
I’m reading about the child themes from the link above. Assuming I’m working with loop-single-X.php and I want to create a child for it. Do I copy that to file to the newsmag-child directory and then put my code in there?
Sorry for the multiple posts, but I think I’m confused. Does this php file:
https://i.imgur.com/2GEVzAw.png
…correspond to this setting?
Hello Ryansmccain,
Before using the child theme you should read the documentation from here -> https://forum.tagdiv.com/the-child-theme-support-tutorial/
Thanks for your understanding!
I read it and I’m still a bit confused.
So the folder newsmag-child is a very specific folder? That signifies to the template that the themes in there are child themes?
Also,
Does this php file:
https://i.imgur.com/2GEVzAw.png
…correspond to this setting?
https://i.imgur.com/BWH5lFA.png
AND
So, which one does it go in?
The post says to put it in loop but that code isn’t in loop.
Thx
-
This reply was modified 7 years by
Ryansmccain.
Hello Ryansmccain,
Do you have read carefully the above documentation? What exactly do you want to achieve? You should replicate core file you want to add into your child theme according to our documentation. Also, if you are not aware of the steps which are needed to take in this case, please consider hiring a freelancer/developer to help you because we cannot provide custom services at the moment, sorry!
Thanks for your understanding!
I did read it. I was asking for clarification. I will do more research on child themes later.
Anyways can you please answer these 2 questions?
Does this php file:
https://i.imgur.com/2GEVzAw.png
…correspond to this setting?
https://i.imgur.com/BWH5lFA.png
I’m nearly 100% certain it does, however, the code that I’m supposed to be looking for it doesn’t appear there.
AND
So, which one does the code go in?
The post says to put it in loop but that code isn’t in loop.
Hello Ryansmccain,
Notice that depends on what kind of post template you are using. You sohuld make the changes on loop single or single template, according to your post template used by you. For example, if you are using the post template 1, the get modified date appears in loop single and for post template 6, the changes should be done in the single-template file as you can see here -> https://www.screencast.com/t/jFgMAFXpyo
Check here -> https://www.screencast.com/t/aW4QuNUhN3QE -> https://www.screencast.com/t/uPw1IhLcjmKU
Thanks.
Thanks for that. I just want to be clear before I look to making changes. I’ll look into child themes after I see that I get it working at all.
I use blog and post template 12: https://i.imgur.com/G0wxURL.png
Based on that, which should I be updating?
Hi Ryansmccain,
Notice that section does not affect the structure of your posts. So, if you will set up your page to be by your latest posts -> https://www.screencast.com/t/1Cckwjn1Ns and if you will make some changes on this section you will affect the modules from your homepage set up by your latest posts. All the changes over your post should be made from loop-single or single template files as I have pointed your above.
Thanks for your understanding!
Hi,
I updated as per codes given in comments but it looks like this,
but i need default views count position and last modified time also please help
https://www.screencast.com/t/7TokcyoYzwhk
website : https://www.b4blaze.com/
-
This reply was modified 7 years by
ayyappancs.
Hi,
You can try using the code below and place it in Theme panel -> Custom CSS area.
.td-post-views{
padding-left: 50%;
}
.the-modified-date{
float:left;
}
The result is here -> https://www.screencast.com/t/C6G1VoouiOcA
Thanks.
That didn’t do anything for me.
Anyways, I spent a ton of time with this. I could get it displaying but then the layout would screwup depending on the resolution, browser, etc. etc.
The best solution for me until this gets put in as an official theme option is this plugin: https://wordpress.org/plugins/wp-last-modified-info/
It dynamically puts the modified date at the top of the post. It’s not ideal, but I have looked at other sites and others do this as well.
You can see what it looks like here:
https://www.interestinganswers.com/science/how-many-people-live-antarctica/