Scroll to success message after submitting contact form (Karma and Sterling Theme)

By default upon submitting a Contact Form the Success Message will display on top of the Page. If your Form is too long, or you have too much content on top of the Form your visitors may not see the Success Message. This script will make the Page automatically scroll to the top upon submitting the Form so the Success Message can be viewed.

For the Karma Theme:

Open up header.php and add the following script before </head>

 <?php if(is_page_template('template_contact_iphone.php')): ?> <script type='text/javascript'> jQuery(window).load(function(){ 	if(jQuery(".message_green").length > 0){     		 jQuery('html').animate({scrollTop: 0 }); 	} }); </script> <?php endif; ?> 

For the Sterling Theme:

Open up header.php and add the following script before </head>

 <?php if(is_page_template('page-template-contact.php')): ?> <script type='text/javascript'> jQuery(window).load(function(){ 	if(jQuery(".success").length>0){     		 jQuery('html').animate({scrollTop: 0 }); 	} }); </script> <?php endif; ?> 

This works only on Karma Theme’s template_contact_iphone.php (Contact iPhone Template). And Sterling Theme’s page-template-contact.php (Contact template). To use for other page template, you will need to change “template_contact_iphone.php” or “page-template-contact.php” in the code to other template file name you are using for the Contact Form.. That’s all.