- This topic has 4 replies, 2 voices, and was last updated 3 years, 6 months ago by
Leo.
-
AuthorPosts
-
September 15, 2021 at 1:14 pm #1931888
Relja
Setup:
Fresh website, with GeneratePress.Problem:
It all works fine with PHP 7.4It also works fine with PHP 8.0, but I get this error in the WP root directory (on the server):
[15-Sep-2021 19:59:44 UTC] PHP Warning: Undefined variable $custom_content in /home/blablabla/public_html/wp-content/themes/generatepress-child/functions.php on line 26
Here’s what’s in line 26 (the bolded line is 26):
// BEGIN LAST-EDITED-updated ISPISIVANJE 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('d/m/Y'); // THE PROBLEMATIC LINE 26: $custom_content .= '<p class="last-updated">Updated: '. $updated_date . '. </p>'; } $custom_content .= $content; return $custom_content; } add_filter( 'the_content', 'wpb_last_updated_date' ); // END LAST-EDITED-updated ISPISIVANJE
The function does its job with no problems, even when that error gets reported in the root directory.
When I install and activate a plugin called “Subscribe To Comments Reloaded,” the error code goes away.
Likewise, if I don’t change anything, just set the PHP back to 7.4 – the problem goes away also.
I’ve checked everything else – PHP extensions, configuration, asked the provider to confirm the 8.0 is running OK.
I use the above-noted plugin on several websites – and they had no problems with the error.log appearing.
That’s how I finally figured out the… strange situation.The problem happens with GeneratePress and with GeneratePress premium.
It doesn’t happen with TwentyTwentyone.September 15, 2021 at 3:14 pm #1931960Relja
When all else fails, read the docs… 🙂
I’ve managed to sort it out. Still have no idea why that code shows error (while it still works) with PHP 8.0, but I’ve completely removed it, and placed this in the child-theme’s style.css:
/* BEGIN updated date showing only */ .posted-on .updated { display: inline-block; } .posted-on .updated + .entry-date { display: none; } .posted-on .updated:before { content: "Updated: "; } /* END updated date showing only */
It works. No “Updated” info on pages, only on posts, but that makes more sense IMO, it’s probably an even better solution. 🙂
Marking this as resolved.
September 15, 2021 at 3:23 pm #1931961Leo
StaffCustomer SupportHi there,
Glad you found a solution.
Just a note that the block element post meta makes it easy for things like these as well.
More info here:
https://docs.generatepress.com/article/block-element-post-meta-template/
https://docs.generatepress.com/article/dynamic-data/September 16, 2021 at 3:37 am #1932368Relja
In case it helps, here’s the full analysis report – what I tested, how I found the problem, how I solved it – with a few dilemmas still left unsolved (but it all works fine now):
https://io.bikegremlin.com/22270/strange-wordpress-php-8-0-error/
September 16, 2021 at 12:11 pm #1933019Leo
StaffCustomer SupportThanks for sharing!
-
AuthorPosts
- You must be logged in to reply to this topic.