Site logo

Archived topic

functions.php error

7 replies · Started by Den on March 20, 2021

Viewing posts 1–8 of 8

Hi team,

Thanks for your 24x7 support.

The thing is, I'm getting an error while saving a code on my functions.php

THE CODE

function myFunction() {
  var element = document.body;
  element.classList.toggle("dark-mode");
}

THE ERROR THAT I AM GETTING


Your PHP code changes were rolled back due to an error on line 84 of file
wp-content/themes/generatepress/functions.php. Please fix and try saving again.

syntax error, unexpected 'var' (T_VAR)

What's the issue? I didn't quite get that. Can you please figure out how do I make it worked?

BTW, this is what i wanna achieve - https://www.w3schools.com/howto/howto_js_toggle_dark_mode.asp

Hi leo,

No, I am editing the Child Theme's function.php

(not the parent theme) :)

Hmm the error you are showing me above is indicating that the error is in the parent theme's function.php:
wp-content/themes/generatepress/functions.php

And there is definitely no error in line 84:
https://github.com/tomusborne/generatepress/blob/master/functions.php#L84

Can you make sure the parent theme's function.php matches the file I linked?

Or you can reinstalling the theme.

Nope, nothing's wrong with my parent theme's function.php (I've just checked it)

It's just when I try to add this code...

function myFunction() {
  var element = document.body;
  element.classList.toggle("dark-mode");
}

- on my website, it just won't let me save that changes because there's some error in var element = document.body; that I'm getting.

See here - https://ibb.co/dbFkCpm

(now it's on the line 49)

------------------------------------------------------

I just want to enable "Toggle Dark Mode" on my website.

and to do this, as per w3schools.com,

I have to add a CSS

body {
  padding: 25px;
  background-color: white;
  color: black;
  font-size: 25px;
}

.dark-mode {
  background-color: black;
  color: white;
}

and a javascript

function myFunction() {
  var element = document.body;
  element.classList.toggle("dark-mode");
}

to enable this function.

Alright, not an issue

Thanks :)

No problem :)

This archived topic is closed to new replies.