Archived topic
Unable to communicate back with site to check for fatal errors
24 replies · Started by MD Tohidul on October 31, 2022
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?
Hi 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/
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 );
That code should still work. Have you tried it?
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 !
Where are you adding the code?
Appearance >> Theme File Editor >> Functions.php
Hi 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:
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 );
Did 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 snippet
How can I understand that I am using a Child Theme?
Go 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.
Still can fixed my issue? Can you help?
Code Snippets is not working with the previous mentioned php code. please tell me how can I fix my issue?
What 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?