The code to render that is <?php the_excerpt(); ?>, so I think what needs to be done is to have my form not render in the context of excerpt generation. What’s the best way to accomplish this?
Alright, in the end, I solved this by checking the stack trace for the presence of the_excerpt, and so I just don’t insert the Gravity Form when I know that my the_content filter is being run in the context of generating the_excerpt. Here’s the full code for posterity:
add_filter('the_content', 'append_gravity_form_to_content', 10);
function append_gravity_form_to_content($content) {
$backtrace = debug_backtrace();
foreach ( $backtrace as $trace ) {
if ( isset( $trace['function'] ) && $trace['function'] == 'get_the_excerpt' ) {
return $content;
}
}
// ... some logic to determine whether the form should be added
$content = $content . do_shortcode('[gravityform id="' . $which_form_value . '" title="false" description="false" ajax="true"]');
return $content;
}
If anyone has a better way to do this, please let me know!
EDIT: ahh, shoot… relying on the value of doing_filter( 'the_excerpt' ) to know whether I need to append the shortcode to $content doesn’t work for me. Specifically: I added a log statement to:
if (doing_filter( 'the_excerpt' )) {
// ... logging statment
}
and it never printed. I have no idea how that’s possible. Perhaps the_excerpt is being called directly, without apply_filter() ?
Anyway, I’ll continue with my stracktrace solution. Thanks so much, Jake Johnson, for your input!