WordPress
HTML
CSS
JavaScript
jQuery
SQL
PHP
WordPress Snippets

Code Snippet

When using Gravity Forms you can decide on a per-form basis as to whether or not you want to automatically scroll to the page top after a form submit.

There are times when a form is towards the bottom of the page and you want the screen to stay in that position so that the user can see the confirmation text. Other times, you may want the page to scroll back to the top because the form is long and the confirmation text will be towards the top.

PHP

Don't Scroll to the Top

Place the following code anywhere in your theme’s functions.php document. Make sure to change the forms to the actual one’s you don’t want to scroll. You can list as many forms here as necessary (we are listing two forms).

				
					// don't scroll to the top of page after submit
add_filter( 'gform_confirmation_anchor_1', '__return_false' );
add_filter( 'gform_confirmation_anchor_4', '__return_false' );
				
			

Do Scroll to the Top

Place the following code anywhere in your theme’s functions.php document. These are the forms we want to scroll back to the page top after begin submitted.

				
					// do scroll to the top of page after submit
add_filter( 'gform_confirmation_anchor_2', function() { inquiry
    return 0;
} );
add_filter( 'gform_confirmation_anchor_3', function() { inquiry
    return 0;
} );
				
			

We’d like to acknowledge that we learned a great deal of our coding from W3Schools and TutorialsPoint, borrowing heavily from their teaching process and excellent code examples. We highly recommend both sites to deepen your experience, and further your coding journey. We’re just hitting the basics here at 1SMARTchicken.

WordPress
HTML
CSS
JavaScript
jQuery
SQL
PHP

Why 1SMARTchicken?

This site was built and is maintained to benefit my autistic son.
See More →

My Son's Name is Johnny

He was diagnosed as autistic quite late, at age four...
His story

Buy Me a Coffee

Thanks for your support!

Feedback

If you see an error on the page or the code itself is incorrect or incomplete, or just plain wrong, please let us know. We’re always learning. NOTE: we do not sell your information and will not send you spam emails.