- This topic has 16 replies, 4 voices, and was last updated 1 year, 3 months ago by
Elvis.
-
AuthorPosts
-
May 14, 2019 at 6:38 am #898902
Hasan
Hi,
Just purchased the pro version of GeneratePress and going to ask a lots of questions, as I am setting up a new photography site!
First question is, how to remove the excerpts completely form the archive pages only? I am using the GeneratePress child theme, and have placed the following code on the functions.php taking from a previous forum post suggestion:
/* Remove excerpts from the achrive pages only */ add_filter( 'wp_trim_excerpt', 'db_excerpt_metabox_remove' ); function db_excerpt_metabox_remove( $excerpt ) { $output = $excerpt; if ( is_archive() && has_excerpt() ) { $output = ''; } return $output; }
But nothing happens. The excerpts are showing as the same.
I’ve set the excerpt length to 0, which is showing “…” and the “read more” link (“show story” in my case). The excerpts are being generated automatically.
Please suggest. Thanks for your help!
Regards,
HasanMay 14, 2019 at 6:48 am #898915David
StaffCustomer SupportHi there,
you won’t need that filter function, thats solely if you’re using a manual excerpt.
The ‘…’ are displayed because of the Read More.
Do you want the read more button showing?May 14, 2019 at 6:53 am #899051Hasan
Thanks David!
I want to remove both the “…” and the read more link.
Best regards,
HasanMay 14, 2019 at 6:54 am #899056David
StaffCustomer SupportRemove the Read more text from the Read More Label in the Customizer so it is empty. This will remove both.
May 14, 2019 at 7:06 am #899073Hasan
That worked perfectly!
Thanks David!! π
May 14, 2019 at 7:06 am #899075David
StaffCustomer SupportYou’re welcome
November 28, 2020 at 10:18 am #1555263Quan
If I want to delete “…” but keep the read more button, what should I do?
November 28, 2020 at 10:23 am #1555277Leo
StaffCustomer SupportTry this CSS:
.entry-summary p:not(.read-more-container) { display: none; }
Adding CSS: https://docs.generatepress.com/article/adding-css/
November 28, 2020 at 10:29 am #1555290Quan
It lost the excerpt section by using the .entry-summary class. I just want to remove the “…” character?
November 28, 2020 at 4:07 pm #1555618Leo
StaffCustomer SupportAny chance you can open a new topic in this case?
Thanks π
February 3, 2022 at 7:52 am #2104027Elvis
Hello,
I would like to remove the excerpt completely, including the wrapper html element. Available wordpress functions that I am able to find show only how to remove the text within the excerpt markup, not the markup itself.Pre get posts allows to replace the template with another template … which is simply more complex way of adding the modified archive.php in child.
I would like to avoid having to create archive.php in my childtheme to do this, and would prefer the hook, function approach. I want to remove html elements that have no purpose from the page for various reasons including accesibility purpose.
Am I missing some method?PhP preg replace?
Thanks in advance.
February 3, 2022 at 8:01 am #2104037David
StaffCustomer SupportHi there,
unfortunately there is no filter to remove the HTML at this time.
You would have to replace the content template – or you can use a Block Element – Content template if you want to avoid PHP in a child theme:https://docs.generatepress.com/article/block-element-content-template/
February 3, 2022 at 9:05 am #2104131Elvis
Thanks David,
for now I will do it like this, and do some more testing for accessibility. JS is not perfect, but apparently sreen readers “talk” to js. If it shows as a not good solution will revert to elements. πadd_filter( 'the_excerpt', 'filter_the_excerpt', 10, 2 ); function filter_the_excerpt( ) { if ( 'people' === get_post_type() && ! is_singular() ) { return; } } add_action('wp_footer', 'remove_excerpt_wrapper'); function remove_excerpt_wrapper() { if ( 'people' === get_post_type() && ! is_singular() ) { ?> <script type="text/javascript"> const postExcerpts = document.querySelectorAll( ".entry-summary" ); postExcerpts.forEach(( element ) => { element.parentNode.removeChild( element ); }); </script> <?php } }
February 3, 2022 at 9:15 am #2104155David
StaffCustomer SupportAs a note –
display: none;
ofvisibility: hidden;
is ignored by a Screen reader.
But it is something we need to address and get rid of superfluous HTML – its on our list πHope that works for you.
February 3, 2022 at 1:03 pm #2104383Elvis
Thanks,
now that you say I think I read this somewhere.
Cool I will add that for a kind of gracefull degradation. π
If js does not work it will still be ok.Enjoy
-
AuthorPosts
- You must be logged in to reply to this topic.