- This topic has 24 replies, 4 voices, and was last updated 2 years, 1 month ago by Ying.
-
AuthorPosts
-
October 31, 2022 at 9:03 am #2395688MD 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 #2395739LeoStaffCustomer 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/October 31, 2022 at 10:06 am #2395767MD TohidulI 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 #2395772LeoStaffCustomer SupportThat code should still work. Have you tried it?
October 31, 2022 at 10:40 am #2395803MD TohidulUnable 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 #2395810LeoStaffCustomer SupportWhere are you adding the code?
October 31, 2022 at 8:31 pm #2396162MD TohidulAppearance >> Theme File Editor >> Functions.php
November 1, 2022 at 2:48 am #2396442DavidStaffCustomer 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:
November 1, 2022 at 2:50 am #2396443MD TohidulThen 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 #2396550DavidStaffCustomer 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 snippetNovember 1, 2022 at 9:46 am #2397048MD TohidulHow can I understand that I am using a Child Theme?
November 1, 2022 at 10:26 am #2397097LeoStaffCustomer 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.
November 3, 2022 at 11:09 am #2400464MD TohidulStill can fixed my issue? Can you help?
November 3, 2022 at 11:39 am #2400493MD TohidulCode 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 #2400499LeoStaffCustomer 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?
-
AuthorPosts
- You must be logged in to reply to this topic.