- This topic has 24 replies, 4 voices, and was last updated 4 months, 3 weeks ago by
Ying.
-
AuthorPosts
-
October 31, 2022 at 9:03 am #2395688
MD Tohidul
Unable to communicate back with site to check for fatal errors, so the PHP change was reverted. You will need to upload your PHP file change by some other means, such as by using SFTP.
After updating the theme, my previous all saved settings gone away. Anyway, I want to show the last updated date of my article.
How can I do this?
October 31, 2022 at 9:45 am #2395739Leo
StaffCustomer SupportHi there,
Anyway, I want to show the last updated date of my article.
Are you using the block editor?
If so using a block element would be the easiest method:
https://docs.generatepress.com/article/block-element-post-meta-template/Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/October 31, 2022 at 10:06 am #2395767MD Tohidul
I found this method is very complex.
I used the following code previously in the PHP Editor, and my work done like magic. How can I do this again?
add_filter( ‘generate_post_date_output’, function( $output, $time_string ) {
$time_string = ‘<time class=”entry-date published” datetime=”%1$s” itemprop=”datePublished”>Published on: %2$s</time>’;if ( get_the_date() !== get_the_modified_date() ) {
$time_string = ‘<time class=”entry-date updated-date” datetime=”%3$s” itemprop=”dateModified”>Last Updated on: %4$s</time>’;
}$time_string = sprintf( $time_string,
esc_attr( get_the_date( ‘c’ ) ),
esc_html( get_the_date() ),
esc_attr( get_the_modified_date( ‘c’ ) ),
esc_html( get_the_modified_date() )
);return sprintf( ‘<span class=”posted-on”>%s</span> ‘,
$time_string
);
}, 10, 2 );October 31, 2022 at 10:15 am #2395772Leo
StaffCustomer SupportThat code should still work. Have you tried it?
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/October 31, 2022 at 10:40 am #2395803MD Tohidul
Unable to communicate back with site to check for fatal errors, so the PHP change was reverted. You will need to upload your PHP file change by some other means, such as by using SFTP.
There is error when tried the code !
October 31, 2022 at 10:42 am #2395810Leo
StaffCustomer SupportWhere are you adding the code?
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/October 31, 2022 at 8:31 pm #2396162MD Tohidul
Appearance >> Theme File Editor >> Functions.php
November 1, 2022 at 2:48 am #2396442David
StaffCustomer SupportHi there,
First off – DO NOT make edits the Themes functions.php. Any changes you make will be lost when the Theme is updated, and you risk breaking the site.
When adding PHP you should read this document:
https://docs.generatepress.com/article/adding-php/
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/November 1, 2022 at 2:50 am #2396443MD Tohidul
Then where should I put the code in the web to show the last updated date of my post?
add_filter( ‘generate_post_date_output’, function( $output, $time_string ) {
$time_string = ‘<time class=”entry-date published” datetime=”%1$s” itemprop=”datePublished”>Published on: %2$s</time>’;if ( get_the_date() !== get_the_modified_date() ) {
$time_string = ‘<time class=”entry-date updated-date” datetime=”%3$s” itemprop=”dateModified”>Last Updated on: %4$s</time>’;
}$time_string = sprintf( $time_string,
esc_attr( get_the_date( ‘c’ ) ),
esc_html( get_the_date() ),
esc_attr( get_the_modified_date( ‘c’ ) ),
esc_html( get_the_modified_date() )
);return sprintf( ‘<span class=”posted-on”>%s</span> ‘,
$time_string
);
}, 10, 2 );November 1, 2022 at 4:09 am #2396550David
StaffCustomer SupportDid you read this article?
https://docs.generatepress.com/article/adding-php/
TLDR: Are you using a Child Theme?
If Yes, then add the snippet to the Child Themes > functions.php
If No, then use the Code Snippets plugin to add that snippetDocumentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/November 1, 2022 at 9:46 am #2397048MD Tohidul
How can I understand that I am using a Child Theme?
November 1, 2022 at 10:26 am #2397097Leo
StaffCustomer SupportGo to Appearance > Themes and see if you are using a child theme there.
I don’t believe so when looking at your replies so the Code Snippets plugin will be the best solution.
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/November 3, 2022 at 11:09 am #2400464MD Tohidul
Still can fixed my issue? Can you help?
November 3, 2022 at 11:39 am #2400493MD Tohidul
Code Snippets is not working with the previous mentioned php code. please tell me how can I fix my issue?
November 3, 2022 at 11:42 am #2400499Leo
StaffCustomer SupportWhat exactly isn’t working when you add the code using Code Snippets?
Any errors?
Can you link us to the page in question and make sure all caching related plugins are disabled?
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/ -
AuthorPosts
- You must be logged in to reply to this topic.