- This topic has 5 replies, 2 voices, and was last updated 4 years, 11 months ago by Leo.
-
AuthorPosts
-
May 20, 2019 at 1:30 pm #905925Sam
Hello,
I’ve found this article: https://docs.generatepress.com/article/activating-read-custom-excerpt/#read-more-text
But when I try to add the two codes in functions.php, I get the following error:
Your PHP code changes were rolled back due to an error on line 129 of file C:\xampp\htdocs\site\wp-content\themes\generatepress\functions.php. Please fix and try saving again.
Cannot redeclare tu_excerpt_metabox_more() (previously declared in C:\xampp\htdocs\site\wp-content\themes\generatepress\functions.php:101)
I’ve added the two codes at the bottom – I’ve installed the Marketeer demo theme with its demo contents.
Thank you in advance!
SamMay 20, 2019 at 1:34 pm #905931LeoStaffCustomer SupportHi there,
Are you adding the code in the theme’s
function.php
file? That’s not a good idea for sure.I just tried adding the code using Code Snippets plugin and didn’t get an error:
Adding PHP: https://docs.generatepress.com/article/adding-php/Can you give it another shot?
Let me know π
May 20, 2019 at 1:45 pm #905940SamHi Leo,
The ”read more text” code works, but when I try to add the ”read more button” code, I get the following error:
Don’t Panic
The code snippet you are trying to save produced a fatal error on line 14:Cannot redeclare tu_excerpt_metabox_more() (previously declared in C:\xampp\htdocs\Site\wp-content\plugins\code-snippets\php\snippet-ops.php(361) : eval()’d code:2)
The previous version of the snippet is unchanged, and the rest of this site should be functioning normally as before.Please use the back button in your browser to return to the previous page and try to fix the code error. If you prefer, you can close this page and discard the changes you just made. No changes will be made to this site.
—
This is the code I try to add:
add_filter( ‘wp_trim_excerpt’, ‘tu_excerpt_metabox_more’ );
function tu_excerpt_metabox_more( $excerpt ) {
$output = $excerpt;if ( has_excerpt() ) {
$output = sprintf( ‘%1$s <p class=”read-more-button-container”>%3$s</p>’,
$excerpt,
get_permalink(),
__( ‘Read more’, ‘generatepress’ )
);
}return $output;
}—
Sorry, I’m not so familiar with php π
Thank you for the fast reply Leo!May 20, 2019 at 1:58 pm #905958LeoStaffCustomer SupportMake sure you are only adding 1 block and not both – if you want the read more buttons, then only add the second block of code.
May 20, 2019 at 2:22 pm #905984SamGot it! Thank you Leo, great support! π
May 20, 2019 at 4:11 pm #906027LeoStaffCustomer SupportNo problem π
-
AuthorPosts
- You must be logged in to reply to this topic.