Syntax error, unexpected '}', expecting end of file When I add Cookie Compliance code

Hi,

I get the following error:
"Your PHP code changes were rolled back due to an error on line 63 of file wp-content/themes/x-child/functions.php. Please fix and try saving again.

syntax error, unexpected ‘}’, expecting end of file"

When I paste and update the following cookie compliance code on my child functions.php file:

add_action( ‘wp_head’, ‘x_insert_header_scripts’ );
function x_insert_header_scripts(){
?>

<?php } Please advise..

Hi Marcos.

Try to login through FTP then go to wp-content/themes/x-child then add the code in the functions.php file.

If this error show’s again your child theme may be updated. You can try downloading the child theme here and install it on the site and move all the customization to the new child theme.
https://theme.co/apex/child-themes

Hope this helps.

Thanks for the quick response!

I just tried that and it closed my site with the following error:
"Parse error: syntax error, unexpected ‘}’, expecting end of file in /home/thefreef/public_html/mysciaticjourney.com/wp-content/themes/x-child/functions.php on line 65

The site is experiencing technical difficulties."

I undid what I just did and my site is back up.

I pasted the following code:
add_action( ‘wp_head’, ‘x_insert_header_scripts’ );
function x_insert_header_scripts(){
?>

<?php } What did I do wrong? How can I avoid that error? ( I have an updated child theme, installed 2 days ago)

Hi Marcos,

Can you please copy all of your content inside your child theme’s functions.php file, paste it into an online code sharing tool like this (https://pastebin.com/) and share your link here to check your issue further.

Thanks!

Hello!

Here you go:

https://pastebin.com/Q4iz2dW3

Hi Marcos,

Update your functions.php file with the following code and it should work.

<?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
// =============================================================================

add_action('wp_head', 'wpb_add_googleanalytics');
function wpb_add_googleanalytics() { ?>

<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-140725938-1"></script>
<script>
  window.dataLayer = window.dataLayer || [];
  function gtag(){dataLayer.push(arguments);}
  gtag('js', new Date());

  gtag('config', 'UA-140725938-1');

</script>

<?php } 

add_action( 'wp_head', 'x_insert_header_scripts' );
function x_insert_header_scripts(){
	?>

<link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/npm/cookieconsent@3/build/cookieconsent.min.css" />
<script src="https://cdn.jsdelivr.net/npm/cookieconsent@3/build/cookieconsent.min.js"></script>
<script>
window.addEventListener("load", function(){
window.cookieconsent.initialise({
  "palette": {
    "popup": {
      "background": "#efefef",
      "text": "#404040"
    },
    "button": {
      "background": "#8ec760",
      "text": "#ffffff"
    }
  }
})});
</script>

<?php
}

I have can also copy it from the following (https://pastebin.com/DMG527uU).

Hope that helps.
Thanks!

Thanks!

Actually, its working, Thank you so much!

You’re most welcome, glad it’s works now. Cheers!

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