- This topic has 7 replies, 2 voices, and was last updated 4 years ago by
Tom.
-
AuthorPosts
-
March 12, 2019 at 4:53 am #836432
Thomas
Hi
I’m having a problem on my site where im shoing blog posts on the frontpage. The excerpt are using a word count of 55, that fits the danish version perfectly. But on our Greenlandic site, that looks awfull. I tried changing it to characters
Then i tried adding this one
function custom_short_excerpt($excerpt){
return substr($excerpt, 0, 200);
}
add_filter(‘the_excerpt’, ‘custom_short_excerpt’);It sort of works, but i lose the read more buttons – are there any other ways of doing it and still get the read more buttons ?
GeneratePress 2.2.2GP Premium 1.7.8March 12, 2019 at 2:06 pm #837081Tom
Lead DeveloperLead DeveloperHi there,
You could try something like this:
add_filter( 'the_excerpt', function( $excerpt ) { $excerpt = substr( $excerpt, 0, 200 ); $button = sprintf( '<p class="read-more-container"><a title="%1$s" class="read-more content-read-more button" href="%2$s">%3$s%4$s</a></p>', the_title_attribute( 'echo=0' ), esc_url( get_permalink( get_the_ID() ) . apply_filters( 'generate_more_jump','#more-' . get_the_ID() ) ), __( 'Read more', 'gp-premium' ), '<span class="screen-reader-text">' . get_the_title() . '</span>' ); return $excerpt . $button; } );
Let me know π
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/
Ongoing Development: https://generatepress.com/ongoing-developmentMarch 13, 2019 at 4:53 am #837505Thomas
Hi Tom,
Thats awesome thanks Alot π it sort of works, i get the read more links now, but i would prefer if i could have the blue buttons like it is as standard, also the standard buttons are wpml compatible so that it gets the translated text, is that possibel somehow ? π
March 13, 2019 at 2:56 pm #838193Tom
Lead DeveloperLead DeveloperI just edited the code above – can you give it another shot?
Let me know π
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/
Ongoing Development: https://generatepress.com/ongoing-developmentMarch 15, 2019 at 4:37 am #839583Thomas
That worked perfectly, now i have the buttons π Do you know if there are there any solutions out there so i can use 2 different code snippets based on the current language so i can translate the button text π ?
March 15, 2019 at 9:43 am #840020Tom
Lead DeveloperLead DeveloperYou could try this:
add_filter( 'the_excerpt', function( $excerpt ) { $excerpt = substr( $excerpt, 0, 200 ); $text = 'Read more'; if ( 'de_DE' === get_locale() ) { $text = 'Read more text for de_DE'; } $button = sprintf( '<p class="read-more-container"><a title="%1$s" class="read-more content-read-more button" href="%2$s">%3$s%4$s</a></p>', the_title_attribute( 'echo=0' ), esc_url( get_permalink( get_the_ID() ) . apply_filters( 'generate_more_jump','#more-' . get_the_ID() ) ), $text, '<span class="screen-reader-text">' . get_the_title() . '</span>' ); return $excerpt . $button; } );
You just need to update
de_DE
to your language, and change the text.Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/
Ongoing Development: https://generatepress.com/ongoing-developmentMarch 15, 2019 at 9:48 am #840032Thomas
Wow that worked perfectly, awesome thanks A lot π
March 15, 2019 at 4:22 pm #840230Tom
Lead DeveloperLead DeveloperYou’re welcome π
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/
Ongoing Development: https://generatepress.com/ongoing-development -
AuthorPosts
- You must be logged in to reply to this topic.