Create Dynamic Post Excerpts with Gravity Forms
Gravity Forms provides an awesome option to create a “Content Template” for the Post Title and Post Body fields; however, the lowly Post Excerpt feel does not have this option.
Here’s a quick snippet which allows you to create your own content template for the Post Excerpt of any post created by a Gravity Form.
Is there a way to add html or css in the excerpt template….trying to replicate the way a byline looks in the content section (using the built in content template available in the content field) Just need to increase text size and/or color for “by {merge code first name} {merge code last name}, {merge code position}, then just leave {merge code body copy} as normal text?
Hi Jeff, I think you’ll need to use this snippet: https://gist.github.com/spivurno/b5c7af4635b781c5bdf9
Hi David,
This is fantastic – thank you for this bit of code. It would be great if $excerpt_template picked up field values instead of field labels.
Are you using a choice-based field? If so, you can use the “:value” modifier. Example: {My Field:1:value}.
Hi David,
Will the snippet also work for custom post type, say the product short description of a Woocommerce product using your plugin Gravity Forms + Custom Post Types?
Yes, sir. :)
I am using this, and it is working great… however I have not found a way to include a line break in the post excerpt.
Any suggestions?
I tested with Twenty Sixteen and line breaks in the Post Excerpt worked as expected. Sounds like it may be a theme issue.
What do the 10,3 digits refer to ?
Hi Grace,
10
is the priority that our function should be run in compared to all other functions bound to this same action.3
refers to the number of parameters that should be passed to our function. This is limited by the number of parameters specified wherever the action/filter is called in the source code.Hey David!
I’m SO excited to find this snippet, as I’ve been searching for a way to use merge tags in excerpts. I put this snippet in the functions.php file and changed the ID to the ID of my form, but nothing seems to have changed. Where should I insert this snippet?
Thank you for all your great work!
Lauren
Hi Lauren, can you confirm this was placed in your theme’s functions.php file? I’ve seen some folks accidentally put this in */wp-includes/functions.php** which won’t work. If you’re sure you put it in the right file, could you send me a URL to your form and a pastie with the contents of your functions.php file?
Hi David,
This works perfectly. Thank you so much for this!
I also want to take a moment to let any of your readers know that you have been an excellent resource to me recently.
I recently had you do some work for me and your approach was very professional and your communications were succinct, timely and courteous. You are a breath of fresh air.
Let the reader understand that I would never hesitate to use David for any GF coding that I need and encourage you to do likewise. You will not be disappointed!
Thanks again David!
Cheers,
Gil Namur President & CEO Life As A Human Inc.
Thanks for the kinds words, Gil. It was a pleasure working with you as well!