SyntaxError: missing } after function body

Hi,

I am having problems with a client’s website where I am getting an error when I insect the page:
SyntaxError: missing } after function body.

eg: https://www.explorermotorhomes.com.au/our-factory/

This error seems to be affecting certain contact forms and ConvertPlus functionality.

Can you please look at this and let me know how to fix it? I added some code to the function.php file a while back to connect a contact form to mailchimp. it was:

<?php

// =============================================================================
// FUNCTIONS.PHP
// -----------------------------------------------------------------------------
// Overwrite or add your own custom functions to X in this file.
// =============================================================================

// =============================================================================
// TABLE OF CONTENTS
// -----------------------------------------------------------------------------
//   01. Enqueue Parent Stylesheet
//   02. Additional Functions
// =============================================================================

// Enqueue Parent Stylesheet
// =============================================================================

add_filter( 'x_enqueue_parent_stylesheet', '__return_true' );



// Additional Functions
// =============================================================================

function my_save_to_mailchimp($form)
{
    if (!class_exists('MCAPI')) {
        require_once dirname(__FILE__) . '/MCAPI.class.php';
    }
 
    $api = new MCAPI('0aa66194b324f0e1acbc1b09161a89dd-us8');    $listId = '47ab272d07';    $email = $form->getValue('iphorm_1_5'); 
    // OPTIONAL: if you are saving additional fields to MC, set the merge tags, otherwise set $mergeVars to an empty array
    $mergeVars = array(
        'FNAME' => $form->getValue('iphorm_1_3'),        'LNAME' => $form->getValue('iphorm_1_4'),      );
 
    // Other settings
    $emailType = 'html';
    $doubleOptin = false;
    $updateExisting = false;
    $replaceInterests = false;
    $sendWelcome = false;
 
    $api->listSubscribe($listId, $email, $mergeVars, $emailType, $doubleOptin, $updateExisting, $replaceInterests, $sendWelcome);
}
add_action('iphorm_post_process_1', 'my_save_to_mailchimp', 10, 1);

Could this be the problem?

Thanks,
Darren.

Hi There,

Thanks for writing in! Could you please post the exact error with line number, so that we should be able to assist you on this.

Thanks!

Hi there,

The error when you inspect element on the page is " SyntaxError: missing } after function body"

The line number that the error appears on changes with each page you view. For this page:


it appears on line 2155, noting that the opening { appears at line 2125

I also notice that when loading a brand new page in cornerstone (no container, with Header & Footer) I get a similar error, saying that the code is a missing “}”.

Thanks.

Hello There,

Thank you for that information. I have checked your site and the error did not came from the code of your child theme’s functions.php file. It is coming from the custom JS code you have added in your site. Please have it updated and make use of this code instead:

(function($) {

	$('#show-more').click(function(e) {
		$('#read-more').toggle();
		$('#show-more').toggle();
	});

	$('#hide-less').click(function(e) {
		$('#read-more').toggle();
		$('#show-more').toggle();
	});

	$('#show-links').click(function(e) {
		$('#popular-searches').toggle();
		$('#show-links').toggle();
		$('#hide-links').toggle();
	});

	$('#hide-links').click(function(e) {
		$('#popular-searches').toggle();
		$('#show-links').toggle();
		$('#hide-links').toggle();
	});


	$(document).ready(function() {
		$("#kk-popular-searches-link").appendTo("footer .x-column.x-md.x-1-4:nth-child(1)");
		$("#kk-popular-searches-link2").appendTo("footer .x-column.x-md.x-1-4:nth-child(1)");
		$("#popular-searches").appendTo("footer");
	});

})( jQuery );

Hope this helps.

Hi,

Thanks so much for looking into this for me. I didn’t add that script - it looks to me like something the SEO people would have done.

I couldn’t see it in the Global JS area. Is there any way to find out where it’s written?

Thanks,
Darren.

Hi There,

Please try testing a plugin conflict. You can do this by deactivating all third-party plugins, and see if the problem remains. If it’s fixed, you’ll know a plugin caused the problem, and you can narrow down which one by reactivating them one at a time.

If it doesn’t help, would you mind providing us with login credentials(by clicking on the Secure Note button at the bottom) so we can take a closer look? To do this, you can make a post with the following info:

  • Link to your site
  • WordPress Admin username / password

Thanks.

Hi,

The code is in your child theme.

Try changing it to this.

jQuery(function($) {
    $('#show-more').click(function(e) {
	$('#read-more').toggle();
$('#show-more').toggle();
});
$('#hide-less').click(function(e) {
	$('#read-more').toggle();
$('#show-more').toggle();
});

$('#show-links').click(function(e) {
	$('#popular-searches').toggle();
$('#show-links').toggle();
$('#hide-links').toggle();
});
$('#hide-links').click(function(e) {
	$('#popular-searches').toggle();
$('#show-links').toggle();
$('#hide-links').toggle();
});


$(document).ready(function() {
$("#kk-popular-searches-link").appendTo("footer .x-column.x-md.x-1-4:nth-child(1)");
$("#kk-popular-searches-link2").appendTo("footer .x-column.x-md.x-1-4:nth-child(1)");
$("#popular-searches").appendTo("footer");

});

Hope that helps.

Hi,

So you are saying replace everything between with the code above?

Thanks,
darren.

Can you please highlight the code that should be replaced by yours?

Thanks,
Darren.

Hi There,

I’ve changed the code.

Your old code:

(function($) {

$('#show-more').click(function(e) {
	$('#read-more').toggle();
$('#show-more').toggle();
});
$('#hide-less').click(function(e) {
	$('#read-more').toggle();
$('#show-more').toggle();
});

$('#show-links').click(function(e) {
	$('#popular-searches').toggle();
$('#show-links').toggle();
$('#hide-links').toggle();
});
$('#hide-links').click(function(e) {
	$('#popular-searches').toggle();
$('#show-links').toggle();
$('#hide-links').toggle();
});


$(document).ready(function() {
$("#kk-popular-searches-link").appendTo("footer .x-column.x-md.x-1-4:nth-child(1)");
$("#kk-popular-searches-link2").appendTo("footer .x-column.x-md.x-1-4:nth-child(1)");
$("#popular-searches").appendTo("footer");


})( jQuery );

My new code:

(function($) {

	$('#show-more').click(function(e) {
		$('#read-more').toggle();
		$('#show-more').toggle();
	});

	$('#hide-less').click(function(e) {
		$('#read-more').toggle();
		$('#show-more').toggle();
	});

	$('#show-links').click(function(e) {
		$('#popular-searches').toggle();
		$('#show-links').toggle();
		$('#hide-links').toggle();
	});

	$('#hide-links').click(function(e) {
		$('#popular-searches').toggle();
		$('#show-links').toggle();
		$('#hide-links').toggle();
	});

	$(document).ready(function() {
		$("#kk-popular-searches-link").appendTo("footer .x-column.x-md.x-1-4:nth-child(1)");
		$("#kk-popular-searches-link2").appendTo("footer .x-column.x-md.x-1-4:nth-child(1)");
		$("#popular-searches").appendTo("footer");
	});

})( jQuery );

Regards!

PERFECT!!

Thanks so much for your help on this one. Much appreciated.

We are gratified that we’re able to help you with this,

Cheers!

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.