Site logo

Archived topic

Dynamic Content - Excerpt - Missing options on dispaly?

15 replies · Started by William on March 27, 2022

Viewing posts 1–15 of 16

Aloha :)

I've built a Block Element >> Content Template for a Catagory Archive display.

I added a Dynamic Content block to display Excerpts.

The excerpts display fine, but neither the Excerpt length (option not having any effect) and 'Read More' ('Use theme more link') link are showing up.

https://cssopps.flywheelsites.com/watermelon/

Any guesses?

Million thanks as always for your assistance :)

- bill, University of Hawai'i

Aloha Leo,

Thanks for the link - sorry for not digging deeper here ... figured it was just me struggling as usual.

I 'activate the read more label' with your code snippet - worked :)

https://docs.generatepress.com/article/activating-read-custom-excerpt/

---

Word count still not working ... I have the Correct Post Format: Standard.

I tried the More button - not sure if it applies in this case - but it had no effect

Thank you again!

bill

Hi Bill,

The Excerpt Word count functionality works if this field is left empty: https://share.getcloudapp.com/E0uoODb6

It doesn’t work if there is a Custom Excerpt set.

Can you try leaving it blank and see how it goes? :)

Hope this clarifies. :)

Aloha Fernando,

That does indeed work ... but I'm using the custom Excerpt specifically to get the exact language I want to display, rather than an auto-pulled chunk by WordPress.

Should I just rethink the way I work?

ie. just make sure that the first sentence or two (depending on final Word count) is what I want to appear on archive pages?

Any other strategies?

Thanks again for your weekend help!!

bill

:)

That would be one option.

Another option is to make sure that the count of the words in the custom excerpt wouldn’t exceed your preference. In other words, you can try using a word counter before placing the custom excerpt.

Example: https://wordcounter.net/

Lastly, instead of the steps above, you can also try adding this PHP snippet to manually trim the length of your custom Excerpt:

function my_trim_excerpt_test($post_excerpt){
	if( ( is_archive() || is_home() ) && ! is_admin() ) {
	return wp_trim_words( $post_excerpt, 4);
	}
	return $post_excerpt;
	
}
add_filter( 'the_excerpt', 'my_trim_excerpt_test');

Kindly replace 4 with your preferred word count.

Adding PHP: https://docs.generatepress.com/article/adding-php/#code-snippets

Adding it through Code Snippets should work.

Hope this helps. :)

Aloha Fernando,

That snippet was exactly what I needed :) THANK YOU!!

Much appreciated!

---

Last Q: Any chance you could tell me how to get rid of these two items at the bottom of a SINGLE POST?

Single Post Items

As always -- the support I find here is second to none!

- bill

Hi Bill,

It looks like something inserted with a hook element/ block element - hook or something generated by a plugin.

Can you try:

1. Deactivate all plugins except GP premium.

2. If it's still there, go to appearance > GeneratePress, deactivate elements module.

3. If step 2 works, re-activate the elements module, go to appearance > elements, check which element is inserting this content.

Let me know if this helps :)

Hum.. that's difficult to tell as we haven't found out what is adding the content.

Any chance you can provide admin access so we can have a look at the backend?

Please keep the plugins deactivated.

Let me know :)

Aloha Ying ... I was just about to write back.

No need to bother you all with this one ... :)

My best guess is that I duplicated and modified the original "Hello World' post.

Fresh blank POSTS are working fine ... I'll just go ahead and redo them.

But thanks a million for your assistance!

Have a terrific week!

- bill

You are very welcome :)

Aloha again :)

So sorry to re-open this one ... I had a quick follow-up.

Fernando offered this code to manually trim excerpts on my archive pages:

function my_trim_excerpt_test($post_excerpt){
	if( ( is_archive() || is_home() ) && ! is_admin() ) {
	return wp_trim_words( $post_excerpt, 4);
	}
	return $post_excerpt;
	
}
add_filter( 'the_excerpt', 'my_trim_excerpt_test');

and it works great!

Is there a way to adjust the code to trim a custom text field called 'general_description' ?

Happy Friday!!!!

- bill

Hi there,

if its a GP Dynamic text field then you could do this:

1. Select the headline block that is displaying the dynamic text, and in Advanced > Additional CSS CLass(es) give it a custom class eg. your-custom-class

2. Add this PHP Snippet:

add_filter( 'generate_dynamic_element_text', function( $text, $block ) {
    if ( ! empty( $block['attrs']['className'] ) && 'your-custom-class' === $block['attrs']['className'] ) {
        $text = wp_trim_words( $text, 4);
    }

    return $text;
}, 10, 2 );

Make sure to update the your-custom-class in your code to match.

Great stuff!!!

Thank you David :)

- bill

This archived topic is closed to new replies.