[Resolved] Read more with custom excerpt not working

Home Forums Support Read more with custom excerpt not working

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #905925
    Sam

    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!
    Sam

    #905931
    Leo
    Staff
    Customer Support

    Hi 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 πŸ™‚

    #905940
    Sam

    Hi 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!

    #905958
    Leo
    Staff
    Customer Support

    Make 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.

    #905984
    Sam

    Got it! Thank you Leo, great support! πŸ™‚

    #906027
    Leo
    Staff
    Customer Support
Viewing 6 posts - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.